-
27-03-08 #1
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:
The page URL is generated through PHP but the title is generated via Javascript. I've now put this text withing aCode:<p class="likeit">Link to this page: <textarea id="codearea" name="codearea" rows="6" cols="60"><a href="<?php echo curPageURL();?>" target="_blank"><?php include ("title.js");?></a></textarea></p>but the javascript breaks it, so instead of displaying the title like it should do, it simply displaysCode:<textarea>
.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 theseems to display correctly.Code:<?php echo curPageURL();?>
Cheers
PhilHancox.co.uk | Affiliate with sites including discount codes, also web developer/designer/etc. | Follow me on Twitter
-
27-03-08 #2
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:
Fingers crossed...!Code:<p class="likeit">Link to this page: <textarea id="codearea" name="codearea" rows="6" cols="60"><a href="<?php echo curPageURL();?>" target="_blank">TITLE</a></textarea></p> <script type='text/javascript'> document.getElementById('codearea').innerHTML = document.getElementById('codearea').innerHTML.replace(/TITLE/,document.title); </script>
-
27-03-08 #3
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
-
27-03-08 #4
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
-
New Vodafone deals on Mobile Rainbow!
By MobileRainbow in forum Affiliate FutureReplies: 0Last Post: 27-04-07, 03:52 PM -
New Vodafone deals on Mobile Rainbow!
By MobileRainbow in forum Affiliate Marketing LoungeReplies: 0Last Post: 27-04-07, 03:43 PM -
PHP/mysql formating problem with paragraphs
By Kandevil in forum ProgrammingReplies: 2Last Post: 25-01-07, 10:48 PM -
using php to print TD javascript code
By J Nas in forum ProgrammingReplies: 2Last Post: 17-03-05, 04:01 PM -
Including a PHP include within a PHP include ??
By madstock in forum ProgrammingReplies: 3Last Post: 17-12-03, 10:00 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks