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

SpaceJump

Well-Known Member
OP
Member
Joined
Aug 18, 2005
Messages
3,866
Trophies
1
Location
Zebes
XP
3,279
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?
 

nIxx

Well-Known Member
Member
Joined
Sep 30, 2007
Messages
1,544
Trophies
0
Location
Germany
Website
Visit site
XP
337
Country
Gambia, The
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
 

camurso_

Well-Known Member
Member
Joined
Dec 23, 2004
Messages
542
Trophies
0
Age
45
XP
460
Country
Portugal
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.
 

SpaceJump

Well-Known Member
OP
Member
Joined
Aug 18, 2005
Messages
3,866
Trophies
1
Location
Zebes
XP
3,279
Country
Germany
Just tried it and it worked! Thanks
smile.gif
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    SylverReZ @ SylverReZ: @OctoAori20, Cool. Same here.