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?

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.

.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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.