Jump to content
Sign in to follow this  
gaby

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>
</form>
</table>

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

checkboxdemo.png

Numai bine :pct2: !

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...