/    Sign up×
Community /Pin to ProfileBookmark

still trying to validate (i suck)

Well I’ve tried more things.
The code has ended up looking like this, and
is still not working…

.. this is a continuation from:
[url]http://www.jsworkshop.com/bb/viewtopic.php?t=617[/url]


****************************

[url]http://www1.gnb.ca/0007/Culture/Heritage/VMC/mailer/sendmail-e.asp[/url]


****************************

[size=1]
function RequiredFields()
{
if( Validate() )
{
// validation passed, allow post
document.frmInfo.submit();
} // validation failed, disallow post return false;
}

function Validate()
{
//— Make sure the Name was entered
if(document.frmInfo.txtName.value.length == 0){
document.frmInfo.txtName.focus();
document.frmInfo.txtName.select();
alert(“You must enter your name to continue.”);
return false;
}
//— Make sure the EMail Address was entered
if(document.frmInfo.txtEMail.value.length == 0){
document.frmInfo.txtEMail.focus();
document.frmInfo.txtEMail.select();
alert(“You must enter an EMail address to continue.”);
return false;
}
//— Make sure the Comments are entered
if(document.frmInfo.txtComments.value.length == 0){
document.frmInfo.txtComments.focus();
document.frmInfo.txtComments.select();
alert(“You must enter your comments to continue.”);
return false;
}
return true;
}
[/size]


***********************************

[size=1]
<form name=”frmInfo” method=”POST” action=”mail.asp”>
<INPUT TYPE=”hidden” NAME=”txtAction” VALUE=””>

<INPUT TYPE=”button” VALUE=”Submit” name=”btnSubmit” onclick=”RequiredFields()”> [/size]


***********************************

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@CharlesFeb 07.2003 — [font=georgia]I took a closer look at your page and two things struck me immediately. To begin with, your HTML is very, very bad. You've got two different pages run together there. Put the following at the top of you page and make sure that it passes the validator at http://validator.w3.org/:

[font=monospace]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

[/font]

It is possible, nay likely, that the page is just too confusing for the JavaScript to work.

The second thing I notice is that you are needlessly making a form that will fail completely when ever JavaScript is absent. You need to be validating from the [font=monospace]onsubmit[/font] handler of the FORM element and you need a real SUBMIT button. JavaScript free users won't get validated but at least they'll be able to submit the form.

[font=monospace]

<form name="frmInfo" method="POST" action="mail.asp" onsubmit="RequiredFields()">

<div>

<INPUT TYPE="hidden" NAME="txtAction" VALUE="">

<INPUT TYPE="submit" VALUE="Submit" name="btnSubmit">

</div>

</form>[/font][/font]
Copy linkTweet thisAlerts:
@khalidali63Feb 07.2003 — Try this..

cheers

Khalid

[upl-file uuid=9b42ae85-e1ff-40e0-a7bb-d440bce3b238 size=2kB]rdharris-validation.txt[/upl-file]
×

Success!

Help @rdharris 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.3,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

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