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

Charles
51.5k13 gold badges107 silver badges146 bronze badges
asked Mar 22, 2011 at 22:37
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
answered Mar 22, 2011 at 22:45
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.

answered Mar 22, 2011 at 22:40

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.

answered Mar 22, 2011 at 22:42

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.