Validating FORM input problem

P

Paul D.Smith

[Resending with different subject to try and tweak someone's interest]

Newbie question I'm afraid. I've got a small form with some simple
JavaScript validating input before submission. Testing it locally, I find
that if I fail validation, I put up an alert() as expected, but still
seem to "refresh" the page _with parameters_. What I mean is that I start
off with the address of the page showing e.g. http://www.me.com/input.html,
hit submit and afterwards, the address shows something like
http://www.me.com/input.html?email=add@domain

I've investigated further and if I set an action, IE does seem to try and
run this action despite my having tried to stop it!

Why am I refreshing and getting these parameters? I seem to be using
"return script()" (which seems to be the main problem) and this doesn't seem
to happen if I change the method to POST.

Any ideas?

Thanks,
Paul DS.
 
N

nice.guy.nige

While the city slept, Paul D.Smith ([email protected]) feverishly
typed...
[Resending with different subject to try and tweak someone's interest]

Newbie question I'm afraid. I've got a small form with some simple
JavaScript validating input before submission. Testing it locally, I
find that if I fail validation, I put up an alert() as expected, but
still
seem to "refresh" the page _with parameters_. [...]

A URL so we can look at your code would be useful. If it isn't already
online, stick it somewhere (even some bobby-basic free space will do for
now) and let us know where.

Cheers,
Nige
 
R

RobM

Paul D.Smith said:
[Resending with different subject to try and tweak someone's interest]

Newbie question I'm afraid. I've got a small form with some simple
JavaScript validating input before submission.
I seem to be using
"return script()" (which seems to be the main problem) and this doesn't seem
to happen if I change the method to POST.

Any ideas?

Thanks,
Paul DS.
Paul, are returning false from the script() function? I assume "return
script()" is defined in your onSubmit on your <form...> tag. If you return
false from your script() after your alert then the form shouldnt submit,
browser goes no further.

Cheers
Rob
 
P

Paul D.Smith

Good point. Here it is since it's not big. Note that even if I get the
alert, I still jump to the index page, or run the appropriate CGI script on
the server when I change the action field.

Paul DS

<head>
<title>Javascript Sample Page</title>
<script language="JavaScript">
<!-- to hide script contents from old browsers
function VerifyData() {
// Source code to check form data goes here.
// Create a variable to keep track of whether the form is valid.
// Initializing this value to 1 means, in effect, that
// the form is valid unless the value changes sometime in the
// routine.
var valid = 1
if (document.Customer.FirstLast.value == "") {
valid = 0
}
// Here we decide whether to submit the form.
if (!valid) {
alert("Please complete all the form fields and enter a valid phone number.")
}
return valid
}

// end hiding contents from old browsers -->
</script>
</head>
<body>
<h2>Sample page for JavaScript Tutorial</h2>
Press the submit button to verify form data.
<p>
<form name="Customer" method="GET" action="file://c:\temp\index.html"
onsubmit="return VerifyData()">
Your name:
<input type="text" name="FirstLast" size="30" maxlength="75" value=""> <br>
<input type="submit">
<input type="reset">
</form>
<p>
</body>
</html>
 
P

Paul D.Smith

Sorted it!

It seems that 0 and false are not the same. Replacing 1 and 0 with true and
false in my example causes it to work.

Hurrah!
 
N

nice.guy.nige

While the city slept, Paul D.Smith ([email protected]) feverishly
typed...
<script language="JavaScript">

Just as an aside, this should be <script type="text/javascript"> to ensure
valid HTML. You can still include the language attribute if you want, but I
don't think there are many browsers out there that will cough if you don't.

Cheers,
Nige
 
K

Karl Groves

Paul D.Smith said:
Sorted it!

It seems that 0 and false are not the same. Replacing 1 and 0 with true
and
false in my example causes it to work.

Hurrah!

Great! Next time, can you show the courtesy of quoting properly so those who
stumble across this thread in the archives can have the benefit of knowing
the context of your message?

-Karl
 
P

Paul D.Smith

Will do. Sorry.

Paul DS.
Karl Groves said:
Great! Next time, can you show the courtesy of quoting properly so those who
stumble across this thread in the archives can have the benefit of knowing
the context of your message?

-Karl
 
K

Karl Groves

Hywel said:
Karl meant like this. Top-posting is evil. It'll make your winkie fall
off.

Well, he also did not quote a message to which he was replying. But yes,
winkies to disappear from top posters..

-Karl
 
M

Mark Parnell

Just as an aside, this should be <script type="text/javascript"> to ensure
valid HTML. You can still include the language attribute if you want, but I
don't think there are many browsers out there that will cough if you don't.

None that I know of. AFAIK in all browsers that support <script>,
Javascript is the default anyway.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top