0

my problem is that, i have a button that contains values and carry it to javascript

here is the code below for the button that carries value 1;

<button onclick="passValue('1')">Pass Me</button>

here is the javascriptfunction that will be called by the button above;
and this script would set the value into a form input;
below the script is the form where the value should be pass.

<script language='javascript'>
function passValue(val){
document.getElementById("myValue").value=val;
}
</script>


<form name="myForm" method="Post" action="getValue.php">
<INPUT TYPE="hidden" name="myVal" id="myValue" />
<INPUT TYPE="submit">
</form>

getValue.php

<?php
echo $_REQUEST['myVal'];
?>

Problem: when the form was submitted to getValue.php, the value displays nothing. in short the value that was set by the javascript function for 'myValue' id is not passed to the getValue.php...

is there anyone who can help me solve this problem?

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by tinker
0

Your code is working fine for me:
or else try with this:

echo $_POST['myVal'];

or

try this:

<form name="myForm" method="Post" action="test12.php">
<INPUT TYPE="hidden" name="myVal" id="myValue" value="0" />
<INPUT TYPE="submit">
</form>

if you click submit without passvalue button , then it displays 0.
if you click submit after clicking passvalue button , then it displays 1.

Edited by Shanti C: n/a

0

.still wont work. the value for $_POST is empty. The value that has been set by the javascript function is not passed when the submit button is clicked!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.