Gaming JavaScript: Only submit a form if a checkbox is checked?

  • Thread starter Thread starter SpaceJump
  • Start date Start date
  • Views Views 2,764
  • Replies Replies 3

SpaceJump

Well-Known Member
Member
Joined
Aug 18, 2005
Messages
3,870
Reaction score
284
Trophies
2
Location
Zebes
XP
3,846
Country
Germany
I want a form to only be submitted if a checkbox is checked. This is what I have so far:

The function:
CODE
ÂÂ


The HTML-Form:
CODE
...
Checkbox

Now if the checkbox is not checked, the message "Checkbox not activated!" comes, but the form is still submitted. How can I prevent this?
 
It´s been a while that i worked with javascript but i think you need something like this



function check()
{
if (document.formular.theCheckbox.checked)
{
alert('Send Form');
return true;
}
else if (...)
{
alert('Not checked...');
return false;
}

return false;
}

if onSubmit gets true it should send if false not
 
That is correct.

If onSubmit returns false, the form won´t be send to the server. All you have to do is to create a function that is called onSubmit and it should return true/false. The event must return, also, true/false.
 
Just tried it and it worked! Thanks
smile.gif
 

Site & Scene News

Popular threads in this forum