hello please help me out regarding this dunction i want to pass value from the textbox to javascript function and over there i want to store it for other text box . here is the sample code '
<input type="button" value="Add" onClick="addRowToTable(<?php echo $data['pno'];?>);" />
here is the javascript function
function addRowToTable(var a)
{
........................
.......................
b.type = 'text';
b.value ='over here how can i get this value of a ';
}
Thanks
3 Answers 3
Use json_encode() : Pass a PHP string to a JavaScript variable (and escape newlines)
Comments
IF your value for $data['pno'] is a string, and not a number type, you need to do
this :
<input type="button" value="Add" onClick="addRowToTable('<?php echo $data['pno'];?>');" />
because you are still passing the value to addRowToTable as a string literal.
Also, what Nick Weaver said--nix the var in the function signature.
1 Comment
Let json_encode() take care about turning your variable in a JavaScript-compatible string:
<input type="button" value="Add" onclick="addRowToTable('<?php echo htmlspecialchars(json_encode($data['pno'])); ?>');" />
PS: If you are using XHTML it's onclick, not onClick.
function addRowToTable(var a)->function addRowToTable(a), does a contain now your value?