NameSilo

JavaScript Checkbox Question

Spaceship Spaceship
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
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
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
•••
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
•••
Yes, I believe thats how it works. (I'm still learning also, so I maybe wrong).
 
0
•••
Appraise.net

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back