/    Sign up×
Community /Pin to ProfileBookmark

Alert Box display problem

Hello,
This alert box has to show up when a certain form is not filled out.
I have this piece of code, but my allert box wont show up ?
could you help me figure it out why ?

[CODE]<SCRIPT LANGUAGE=”JavaScript”>
function verify() {
var themessage = “Trebuie sa complectezi urmatoarele campuri: “;
if (document.form.nume.value==””) {
themessage = themessage + ” – Nume”;
}
if (document.form.prenume.value==””) {
themessage = themessage + ” – Prenume”;
}
if (document.form.varsta.value==””) {
themessage = themessage + ” – Varsta”;
}
if (document.form.email.value==””) {
themessage = themessage + ” – E-mail”;
}
else if (document.form.email.value.indexOf(‘@’)==-1) {
themessage = themessage + ” – E-mail (invalid)”;
}
if (document.form.tel.value==””) {
themessage = themessage + ” – Telefon”;
}
if (document.form.transport.value==””) {
themessage = themessage + ” – Transport”;
}
if (themessage == “Trebuie sa complectezi urmatoarele campuri: “) {
document.form.submit();
else {
alert(themessage);
return false;
}
}
</script>

</head>
<body>
<div align=”center”> <img src=”/rev/lg.png” title=”Revelion 2008-2009″ alt=”Revelion 2008-2009″ /> </div>

<div align=”center”><font size=”+2″ color=”#99CC33″>Pasul Inscrierii</font></div>
<div align=”center”><font size=”-1″ color=”#99CC33″>(Te rugam sa complectezi fiecare camp)</font></div>
<br>
<div align=”center”>
<form action=”/rev/lista/index.php” method=”post” name=”form” ENCTYPE=”text/plain” onClick=”verify();”>
Numele:<span class=”style1″>*</span> <input type=”text” name=”nume” id=”nume” style=”margin-left:25px” />
<br>
Prenumele:<span class=”style1″>*</span> <input type=”text” name=”prenume” id=”prenume” style=”margin-left:3px” />
<br>
Varsta:<span class=”style1″>*</span> <input type=”text” name=”varsta” id=”varsta” maxlength=”2″ style=”margin-left:35px”/>
<br>
CNP: <input type=”text” name=”cnp” maxlength=”13″ id=”cnp” style=”margin-left:57px”/><br>
Telefon:<span class=”style1″>*</span> <input type=”text” id=”telefon” name=”telefon” maxlength=”10″ style=”margin-left:25px”/>
<br>
E-mail:<span class=”style1″>*</span> <input type=”text” name=”email” id=”email” style=”margin-left:32px” />
<br>
<font style=”font-size: 15px”>Necesita Transport DA/NU:<span class=”style1″>*</span></font> <input type=”text” name=”transport” id=”transport” maxlength=”2″ style=”width:25px; margin-left:47px” />
<br><br>

<input type=”submit” value=”Inscrie” onClick=”verify();”/>
<input type=”reset” value=”Resetare Campuri”/>

</form>[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@MrNobodyNov 26.2008 — This is incorrect:
[code=html]<form action="/rev/lista/index.php" method="post" name="form"
ENCTYPE="text/plain" onClick="verify();">[/code]

Change that to this:
[code=html]<form name="myform" action="/rev/lista/index.php" method="post"
ENCTYPE="text/plain" onsubmit="return verify(this.elements)">[/code]

Then change your function to this:
[CODE]function verify(f)
{
var ele = f.elements;
var themessage = "Trebuie sa complectezi urmatoarele campuri: ";
if (ele['nume'].value=="") themessage += " - Nume";
if (ele['prenume'].value=="") themessage += " - Prenume";
if (ele['varsta'].value=="") themessage += " - Varsta";
if (ele['email'].value=="") themessage += " - E-mail";
else if (ele['email'].value.indexOf('@')==-1) themessage += " - E-mail (invalid)";
if (ele['tel'].value=="") themessage += " - Telefon";
if (ele['transport'].value=="") themessage += " - Transport";
if (themessage == "Trebuie sa complectezi urmatoarele campuri: ") {
f.submit();
return true;
}
alert(themessage);
return false;
}[/CODE]
×

Success!

Help @szabika spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...