/    Sign up×
Community /Pin to ProfileBookmark

Validation before submission to database

I am trying to validate a form on an asp page before it is submitted to the database but it is not working. The code is in an external javascript page and looks like this –

<!–

function check()
{
x=document.details;
player=x.player;
position=x.position;
club=x.club;
value=x.val;

ok=”true”
if (player.length<1)
{
alert(“Must enter Player’s Name”)
ok=”false”
}

if (position.length<1)
{
alert(“Invalid position”)
ok=”false”
}

if (club.length<1)
{
alert(“Invalid club name”)
ok=”false”
}

if (val.length<1)
{
alert(“Must be entered to one decimal place eg 3.1”)
ok=”false”
}
}

// –>

the page that calls the function looks like this :-

<html>
<head>
<script src=”useful.js”>
</script>
</head>
<body><form name=”details” method=”post” enctype=”text/plain” action=”demo_add.asp” onsubmit=”return check()”>
<table>
<tr>
<td>Player Name:</td>
<td><input name=”player”></td>
</tr><tr>
<td>Position:</td>
<td><input name=”position”></td>
</tr><tr>
<td>Club:</td>
<td><input name=”club”></td>
</tr><tr>
<td>Value:</td>
<td><input name=”val”></td>
</tr>
</table>
<br /><br />
<input type=”submit” value=”Add New”>
<input type=”reset” value=”Clear”>

</form>
</body>
</html>

If I leave the form blank, I get the following error :-

Error Type:
Microsoft JET Database Engine (0x80040E07)
Data type mismatch in criteria expression.
/demo_add.asp, line 12

Does anyone have any ideas?? The function works because it validates another form but for some reason it will not execute the function before it tries submitting the data to the database.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@PittimannApr 21.2004 — Hi!

You could try something like this:
[code=php]
function check()
{
x=document.details;
player=x.player.value;
position=x.position.value;
club=x.club.value;
val=x.val.value;
msg='';
ok="true"
if (player.length<1)
{
msg="Must enter Player's Name"+"n";
ok="false"
}

if (position.length<1)
{
msg +="Invalid position"+"n";
ok="false"
}

if (club.length<1)
{
msg +="Invalid club name"+"n";
ok="false"
}

if (val.length<1)
{
msg +="Must be entered to one decimal place eg 3.1"+"n";
ok="false"
}
if (ok=="false"){
alert(msg);
return false;
}
return true;
}
[/code]

Cheers - Pit
Copy linkTweet thisAlerts:
@jaegernautApr 21.2004 — I don't see where you are returning the value so that it will stop the submit process in a false situation.

I would expect a "return false" somewhere to stop the submit and allow the user to make the noted changes.

<<<<<< edit >>>>>>

Doh, Pit you beat me to the punch. ?

<<<<<<< /edit >>>>>
Copy linkTweet thisAlerts:
@PittimannApr 21.2004 — Hi jaegernaut!

I did so just to tease you :p

Greetz! Pit
×

Success!

Help @PhilC797 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.17,
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,
)...