0

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

1
  • 3
    Try changing your function head from function addRowToTable(var a) -> function addRowToTable(a), does a contain now your value? Commented Mar 22, 2011 at 22:40

3 Answers 3

2

Use json_encode() : Pass a PHP string to a JavaScript variable (and escape newlines)

Sign up to request clarification or add additional context in comments.

Comments

2

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

Thanks .It is no . so what else i need to do
2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.