jcbodyworks
asked on
JavaScript checkbox help value PHP AJAX
I need help getting the value of a checkbox in a form I have. The HTML code for the checkbox is:
<INPUT TYPE="CHECKBOX" NAME="agreement" id="agreement" VALUE="iagree">
The JavaScript code is:
var obj15 = document.getElementById("a greement") ;
var agreement = obj15.value;
The PHP code to validate this is:
$agreement=$_POST['agreeme nt'];
if ($agreement=="")
{
echo 'document.getElementById(" emailsent" ).innerHTM L = "You must agree to our Legal Notice and Privacy Statement before submission.";';
return;
}
Now, the issue is that I cant get the JavaScript right to get the value of the checkbox. I need some help with this. Thanks. Also, if when you help me, please let me know what the value of false would be, is it an empty string?.... "" ? Thanks
<INPUT TYPE="CHECKBOX" NAME="agreement" id="agreement" VALUE="iagree">
The JavaScript code is:
var obj15 = document.getElementById("a
var agreement = obj15.value;
The PHP code to validate this is:
$agreement=$_POST['agreeme
if ($agreement=="")
{
echo 'document.getElementById("
return;
}
Now, the issue is that I cant get the JavaScript right to get the value of the checkbox. I need some help with this. Thanks. Also, if when you help me, please let me know what the value of false would be, is it an empty string?.... "" ? Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Have you used the same id multiple times --> (id="agreement" ). Verify, if that is the case try giving unique ids and check them
Another thing is your javascript code a part of the file that is called by Ajax. In that case you should move your javascript code to some other js file.