Jump to content

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


gaby

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: !

  • Upvote 1

Te-ai inregistrat? Ne-ar placea sa te prezinti.

Cum pot sustine forumul?
Cumpara de la eMag folosind acest link.
--------------------
oG2BN9d.gifse1WdXd.gifQG6MtmI.gifRHYjDzD.gifG5p1wui.gif

Link to comment
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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.