Jump to content

Noob request i know ...


iPixel

Recommended Posts

I've got 2 radio buttons...

 


Agreement txt here Agreement txt here Agreement txt here Agreement txt here 
Agreement txt here Agreement txt here Agreement txt here Agreement txt here 
Agreement txt here Agreement txt here Agreement txt here Agreement txt here 

<form action="#" method="POST">
<input type="radio" value="YES" name="agreement">YES <br />
<input type="radio" value="NO" name="agreement">NO <br />
<input type="submit" value="Submit" name="submit" />
</form>

 

No what i want is that unless the "YES" radio button is checked... pop up an alert saying u must agree to continue.

 

the weird thing, ok..

 

I used


function chkAgreement()
  {
     alert('You must agree to the terms before you continue');
  }

but even after you hit OK it just goes to where the action points...

 

confirm('msg') i dont really want to use because i dont want the cancel button there.. just the OK.

 

So how do i prevent the form being submitted unless the YES radio button is selected.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/70521-noob-request-i-know/
Share on other sites

I believe what you need is a conditional in your chkAgreement() function that checks to see if your checkbox is checked. Just off the top of my head, haven't tested it or anything. Then, instead of using a submit button simply tie your button to your JS function and use the JS to submit the form if the appropriate field is checked.

 

function chkAgreement() {
    if (document.myform.agreement.value=='YES') {
        document.myform.submit();    
    } else {
        alert('You must agree to the terms before you continue');
        return false;
    }
}

Link to comment
https://forums.phpfreaks.com/topic/70521-noob-request-i-know/#findComment-354572
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.