JavaScript Checkbox Question

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Watch

devanium

Established Member
Impact
0
Does anyone know how I can use JavaScript to make sure a checkbox is checked before a form is allowed to be submitted? Also, if the button already has an onClick element, can I add a second one, or do I have to modify the onClick script it's referring to to include the checkbox JavaScript too?

Any help is appreciated, thanks
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Try something like this:

Code:
if(window.document.example1.my_checkbox.checked=true)
{
alert('The box is checked!')
}
else
{
window.document.example1.my_checkbox.checked=true;
alert('The box was not checked!');
}
 
0
Close
Fewski said:
Try something like this:

Code:
if(window.document.example1.my_checkbox.checked=true)
{
alert('The box is checked!')
}
else
{
window.document.example1.my_checkbox.checked=true;
alert('The box was not checked!');
}

So I would have that as a javascript file at the top of the page, and then have the onClick on the submit button for the form?
 
0
Close
Yes, I believe thats how it works. (I'm still learning also, so I maybe wrong).
 
0
Close
Appraise.net

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back