Jump to content
Sign in to follow this  

Verificare Bifare Checkbox On Submit / Only Submit If A Checkbox Is Checked

Recommended Posts

Pornind de la cererea de aici: , a trebuit sa fac 2 casute (checkbox) care daca nu erau validate sa returneze un mesaj de eroare, astfel utilizatorul fiind obligat sa le bifeze pentru ca datele introduse in contact form sa fie trimise.

Ei bine codul javascript (introdus intre etichetele <head></head> trebuie sa arate asa:

<script type="text/javascript"> 
function validate(form) {
// Checking if at least one period button is selected. Or not.
if (!document.form1.agree1.checked || !document.form1.agree2.checked){

alert("Te rugam marcheaza ambele casute!");
return false;}

return true;
</script>[/code] iar codul [b]html[/b], asa:
[code]<table border="1" width="50%" cellspacing="1" cellpadding="1" >
<form name="form1" method="post" action="send.php" onsubmit="return validate(this)">
<tr><td align="center" bgcolor="#f1f1f1"><font face="verdana" size="2"><input type="checkbox" name="agree1">Da, vreau ciocolata.</td></tr>
<tr><td align="center" bgcolor="#f1f1f1"><font face="verdana" size="2"><input type="checkbox" name="agree2">Da, vreau si cirese.</td></tr>
<tr bgcolor='#ffffff'><td align="center" ><input type="submit" value="Submit"> <input type="reset" value="Reset"></td></tr>

Daca niciuna sau doar una dintre casute este bifata, efectul va fi:


Numai bine :pct2: !

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.