Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

JavaScript Checkbox Question

SpaceshipSpaceship
SpaceshipSpaceship
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
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Member card: see how many threads a member started
The member card now shows a Threads number, right after Posts. The member card is the box that opens when you point at a name. Profile...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back