1

I want to send 2 variables when clicking on a button. below is my code

$value=$document["rootFolder"];
$value2=$document["uploadSize"];


$_SESSION['rootFolder']=$value;

  echo '<input type="image" src="images/file2.png"  class="btTxt submit" width="85" onclick="myfunc('.$value2.','.$value.')"><b> '.$value . "</b>";
echo "</tr>";

}

below is my fuction:

<script type="text/javascript">

        function myfunc(size, fname){ 
                var name=fname;

                var m = parseInt(size);
                var size2 = (m).toString();

        alert(name);

Why am I not able to call the 2nd parameter that is fname? This works fine when I pass only one parameter that is size.

4
  • The name parameter is most likely text, so you need to wrap it in quotes. This is where creating inline code gets really awkward but you can at least do it like this: echo "<input ... onclick='myfunc($size, \"$value\")'>..."; It's way better to assign the click handler with JavaScript though. Commented Mar 10, 2020 at 11:39
  • Example code: ideone.com/z1yGn0 Commented Mar 10, 2020 at 11:54
  • its not working Commented Mar 10, 2020 at 12:25
  • @mishty if that's all the information you're going to tell us, then we cannot help you further. Provide some proper debugging info pleaase. e.g. sample data, the rendered HTML of your function (via the browser's View Source tool), and any errors you are seeing in the browser's Console. These are basic checks you should be making already. Commented Mar 10, 2020 at 13:12

2 Answers 2

1

You can alert both values easily:

function myfunc(size, fname) {
  alert(size);
  alert(fname);
}
<input type="image" src="images/file2.png" class="btTxt submit" width="85" onclick="myfunc('7','8')">

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

Comments

0
$value="'".$document["rootFolder"]."'";   //assuming value $document["rootFolder"] = "path/to/root/folder" is string;
$value2=$document["uploadSize"];  //assuming value $document["uploadSize"] = 400 is integer;

in your code just changed

$value=$document["rootFolder"]; to $value="'".$document["rootFolder"]."'";

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.