Link to home
Create AccountLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

Radio Button Javascript

I have a form  with a radio button (and of course other fields).

The form statement:

<form method="POST" action="http://www.rain1.com/new-site/authorize_net.php" name="st" onSubmit="return validate_pmnt_form();">

The radio button:

Please note:  Service packages are non refundable and non transferable.&nbsp;&nbsp; <input type="radio" name="ntr" value="y" style="visibility; visible;">&nbsp;&nbsp;  Click to indicate you have read this statement.

The javascript (in function validate_pmnt_form)

if (!document.st.ntr[0].checked) {
      alert("Please click that you understand the non-refundable & non-transferrable statement.");
                        return false;
                  }
If you DO NOT click the radio button, it still submits the form.

What's wrong?

Thanks
Avatar of Richard Korts
Richard Korts
Flag of United States of America image

ASKER

I changed the javascript to:

if(!document.getElementById('ntr_read').checked) {
                        alert("Please click that you understand the non-refundable & non-transferrable statement.");
                        return false;
                  }      

and gave the radio button an id of ntr_read & it worked.

I'd still like to know why the original did NOT work.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account