Hi Guys,
Help !
I am trying to pass a variable in a function from php/html to javascript,
$loginsummary .= "
<table>
<tr>
<td><input name='user' type='text' id='user' value='' onChange='doit('hello')' /></td>
The problem seems to be with how many apostrophes is before 'hello' the function works if I remove the hello part so it is fine calling it, i just need to be able to set a variable.
Kind Regards,
C
Referencing a javascrip variable in html within PHP
Moderator: General Moderators
Re: Referencing a javascrip variable in html within PHP
You need double quotes around the string inside the doit() function, otherwise the single quote before the hello closes the onChange statement:
Also, if that is within a php string (I can't quite work out what you're trying to do from your code) you'll need to escape the double quotes with a backslash, to stop them closing the php string:
Code: Select all
onChange='doit("hello")'Code: Select all
onChange='doit(\"hello\")'