/    Sign up×
Community /Pin to ProfileBookmark

Javascript email form

Can anyone please help me?

I have this form, which works fine, but the problem is that whenever you click the submit button the email is sent even if nothing is written in the form.

How can i change this into having (maybe with javascript?) it check if the form is filled before submiting.

<form action=”http://blahblah.dll” method=”POST”>
<input type=hidden name=”mail-to” value=”[email protected]“>
<input type=hidden name=”mail-from” value=”text”>
<input type=hidden name=”mail-subject” value=”text”>
<input type=hidden name=”mail-success” value=”http://success.htm“>
<div align=”left”>
<p>Nome:<br>
<strong>
<input name=”Nome” type=”text” id=”Nome” size=”20″ maxlength=”35″>
<br>
<br>
</strong> E-mail:<strong><br>
<input name=”E-mail” type=”text” id=”E-mail” size=”20″ maxlength=”35″>
<br>
<br>
<input type=”submit” name=”Submit” value=”Enviar”>
</strong></p>
</div>
</form>

help would be really apreciated, thanks,

cogumelo

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@96turnerriNov 15.2004 — in the head

<script type="text/javascript">

function validate_form() {

if(document.getElementById('Nome').value=="" || document.getElementById('E-mail').value=="") {

return false;

}

return true;

}

</script>

add this to form tag

onsubmit="return validate_form;"
Copy linkTweet thisAlerts:
@cogumeloauthorNov 16.2004 — thanks for the quick answer!

however i'll nag you all a bit more :o

how can it be modified into confirming the format of the email the "@" and "."

<script type="text/javascript">

function validate_form() {

if(document.getElementById('Nome').value=="" || document.getElementById('E-mail').value=="") {

return false;

}

return true;

}

</script>

thanks in advance for all the help


regards,

cogumelo
Copy linkTweet thisAlerts:
@96turnerriNov 16.2004 — untested but should work

<script type="text/javascript">

function validate_form() {

if(document.getElementById('Nome').value=="" || document.getElementById('E-mail').value=="" || !/^w+([.-]?w+)*@w+([.-]?w+)*(.w{2,3})+$/.test(document.getElementById('E-mail').value)) {

return false;

}

return true;

}

</script>
Copy linkTweet thisAlerts:
@cogumeloauthorNov 16.2004 — Works like a charm

thanks for the quick help.


regards,

cogumelo
Copy linkTweet thisAlerts:
@96turnerriNov 16.2004 — your welcome
×

Success!

Help @cogumelo 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 6.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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...