Page 1 of 1

PHP and JS

Posted: Tue Oct 13, 2009 9:37 am
by robamacaf
I have a textbox on my html site that is named q. I want it that when people click on this link it will put the text of that link into the box.

This works:
<a href='#' onclick="javascript: document.getElementById('q').value = 'test';"><?php echo $firstName;?></a>
it puts the word test into the box named q

But this doesnt:
<a href='#' onclick="javascript: document.getElementById('q').value = '<?php echo $firstName;?>';"><?php echo $firstName;?></a>

Might anyone know why?

Thanks in advance
Rob

Re: PHP and JS

Posted: Tue Oct 13, 2009 10:32 am
by kaszu
First name has quotes in it? Try this:

Code: Select all

<?php echo addslashes($firstName);?>

Re: PHP and JS

Posted: Tue Oct 13, 2009 10:35 am
by robamacaf
kaszu wrote:First name has quotes in it? Try this:

Code: Select all

<?php echo addslashes($firstName);?>
firstname is just a string. I will be using it to hold ID numbers, it is usually something like a34234 or a12315 etc

Re: PHP and JS

Posted: Tue Oct 13, 2009 11:17 am
by kaszu
Then it should work.

Re: PHP and JS

Posted: Tue Oct 13, 2009 11:34 am
by jackpf
This is a double post btw..

Here's the other: viewtopic.php?f=1&t=107512

Don't double post please. There are numerous reasons why it isn't allowed...read the forum rules for more info.