PHP and JS

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
robamacaf
Forum Newbie
Posts: 2
Joined: Tue Oct 13, 2009 9:35 am

PHP and JS

Post 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
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: PHP and JS

Post by kaszu »

First name has quotes in it? Try this:

Code: Select all

<?php echo addslashes($firstName);?>
robamacaf
Forum Newbie
Posts: 2
Joined: Tue Oct 13, 2009 9:35 am

Re: PHP and JS

Post 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
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: PHP and JS

Post by kaszu »

Then it should work.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: PHP and JS

Post 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.
Post Reply