1. #1
    philhancox is an unknown quantity at this point philhancox's Avatar Registered User
    Join Date
    Oct 2007
    Posts
    502
    Thanks
    2
    Thanked 17 Times in 15 Posts

    Including javascript (or php) within text area

    I currently have a snippet of text displayed on every page that automatically generates a link for them to use:

    Code:
    <p class="likeit">Link to this page: <textarea id="codearea" name="codearea" rows="6" cols="60">&lt;a href="<?php echo curPageURL();?>" target="_blank"&gt;<?php include ("title.js");?>&lt;/a&gt;</textarea></p>
    The page URL is generated through PHP but the title is generated via Javascript. I've now put this text withing a
    Code:
    <textarea>
    but the javascript breaks it, so instead of displaying the title like it should do, it simply displays
    Code:
    <script language="JavaScript">
    document.write (document.title)
    </script>
    .

    Is there a way of including the JS within the textarea so it actually works properly, or put it within a php statement, as the
    Code:
    <?php echo curPageURL();?>
    seems to display correctly.

    Cheers
    PhilHancox.co.uk | Affiliate with sites including discount codes, also web developer/designer/etc. | Follow me on Twitter

  2. #2
    dmorison is an unknown quantity at this point Registered User
    Join Date
    Mar 2004
    Location
    Stafford, UK
    Posts
    320
    Thanks
    1
    Thanked 2 Times in 1 Post
    Hi,

    You won't be able to include JavaScript into the page within a TEXTAREA tag as all markup between those tags is displayed "asis", as you've discovered...

    The first way I can think of to do this is to use JavaScript to update the text, substituting a placeholder (that you write in when generating the page) with document.title.

    Try this:

    Code:
    <p class="likeit">Link to this page: <textarea id="codearea" name="codearea" rows="6" cols="60">&lt;a href="<?php echo curPageURL();?>" target="_blank"&gt;TITLE&lt;/a&gt;</textarea></p>
    <script type='text/javascript'>
    document.getElementById('codearea').innerHTML = document.getElementById('codearea').innerHTML.replace(/TITLE/,document.title);
    </script>
    Fingers crossed...!

  3. #3
    philhancox is an unknown quantity at this point philhancox's Avatar Registered User
    Join Date
    Oct 2007
    Posts
    502
    Thanks
    2
    Thanked 17 Times in 15 Posts
    Haha, it doesn't matter whether it's here or the PT forums - you still answer extremely quickly and with a solution that works
    Sir, you are a genius and a star. Thanks very much!
    PhilHancox.co.uk | Affiliate with sites including discount codes, also web developer/designer/etc. | Follow me on Twitter

  4. #4
    dmorison is an unknown quantity at this point Registered User
    Join Date
    Mar 2004
    Location
    Stafford, UK
    Posts
    320
    Thanks
    1
    Thanked 2 Times in 1 Post
    I'll do anything to satisfy my daily coding fix!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. New Vodafone deals on Mobile Rainbow!
    By MobileRainbow in forum Affiliate Future
    Replies: 0
    Last Post: 27-04-07, 03:52 PM
  2. New Vodafone deals on Mobile Rainbow!
    By MobileRainbow in forum Affiliate Marketing Lounge
    Replies: 0
    Last Post: 27-04-07, 03:43 PM
  3. PHP/mysql formating problem with paragraphs
    By Kandevil in forum Programming
    Replies: 2
    Last Post: 25-01-07, 10:48 PM
  4. using php to print TD javascript code
    By J Nas in forum Programming
    Replies: 2
    Last Post: 17-03-05, 04:01 PM
  5. Including a PHP include within a PHP include ??
    By madstock in forum Programming
    Replies: 3
    Last Post: 17-12-03, 10:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Content Relevant URLs by vBSEO 3.5.0 RC2