0

Heres my current code in php with one parameter which works

 <?php
  $sid = "012";
  echo '<input type="button" value="Submit" onclick="changeConfirmed('.$sid.')">';

?>

Now im trying to pass two parameters or more, but cant seem to get it to work, here is my attempt:

 <?php
  $name="abc
  $sid = "012";
  echo '<input type="button" value="Submit" onclick="changeConfirmed('.$sid.','.$name.')">';

?>
2
  • can you post the changeConfirmed function definition too? Commented Nov 29, 2016 at 21:47
  • "cant seem to get it to work" is an insufficient problem description. Please clearly state what you would expect and what the result is instead. Edit the question to include the changeConfirmed function and possibly any error that is triggered. Commented Nov 29, 2016 at 22:03

2 Answers 2

3

You need quotes around the parameters or javascript treats them like variables instead of strings.

echo '<input type="button" value="Submit" onclick="changeConfirmed(\''.$sid.'\',\''.$name.'\')">';
Sign up to request clarification or add additional context in comments.

Comments

2

If one of your JavaScript function parameters is a string, you'll have to correctly enclose it in quotes:

<?php
  $name="abc";
  $sid = "012";
  echo '<input type="button" value="Submit" onclick="changeConfirmed('.$sid.',\''.$name.'\')">';
?>

You get away with $sid not enclosed in quotes because it looks like a number.

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.