Link to home
Start Free TrialLog in
Avatar of jcbodyworks
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("agreement");
      var agreement = obj15.value;

The PHP code to validate this is:

$agreement=$_POST['agreement'];
if ($agreement=="")
{
echo 'document.getElementById("emailsent").innerHTML = "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
ASKER CERTIFIED SOLUTION
Avatar of steelseth12
steelseth12
Flag of Cyprus image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.