|
 |
asp_web_howto thread: Need help ASAP with form submit through javascript function.
Message #1 by "Christopher Cote" <cotec@s...> on Thu, 17 Jan 2002 15:26:27
|
|
I have a form with javascript code to make sure that the form is filled in
correctly. If it isn't I don't want the form to go ahead submit. There
are 2 text boxes. If the user types text into one of them, he must input
something into the other one in order for it to work correctly. The other
option is to leave both text boxes blank. I can't figure out how to make
sure the form doesn't continue if the form is filled in wrong.
Can someone please help?
Chris
Message #2 by "Eric Van Camp" <eric@a...> on Thu, 17 Jan 2002 16:33:42 +0100
|
|
make a javascript that displays a warning box on the screen,that when
nothing is filled in and that the user wants to send the form.
if something is filled in in the first text box, let the javascript display
a warning box on the screen when nothing has been filled in !
-----Original Message-----
From: Christopher Cote [mailto:cotec@s...]
Sent: Thursday, January 17, 2002 15:26
To: ASP Web HowTo
Subject: [asp_web_howto] Need help ASAP with form submit through
javascript function.
I have a form with javascript code to make sure that the form is filled in
correctly. If it isn't I don't want the form to go ahead submit. There
are 2 text boxes. If the user types text into one of them, he must input
something into the other one in order for it to work correctly. The other
option is to leave both text boxes blank. I can't figure out how to make
sure the form doesn't continue if the form is filled in wrong.
Can someone please help?
Chris
$subst('Email.Unsub').
Message #3 by Oleg Kapeljushnik <c-oleg.kapeljushnik@w...> on Thu, 17 Jan 2002 10:37:13 -0500
|
|
you can use onsubmit event
<form onsubmit="return checkfunc();">
now you can create checkfunc() function and make all data validation
that you need and then return true if everything ok or return false if you
have an error.
If true was return form will be submitted and if its false no action will
done.
There are also few other ways like you can use onchange event and check it
right away.
Or create some button for submitting your form and then create onclick event
so you could
check you form before you submit it.
Oleg.
-----Original Message-----
From: Christopher Cote [mailto:cotec@s...]
Sent: January 17, 2002 3:26 PM
To: ASP Web HowTo
Subject: [asp_web_howto] Need help ASAP with form submit through
javascript function.
I have a form with javascript code to make sure that the form is filled in
correctly. If it isn't I don't want the form to go ahead submit. There
are 2 text boxes. If the user types text into one of them, he must input
something into the other one in order for it to work correctly. The other
option is to leave both text boxes blank. I can't figure out how to make
sure the form doesn't continue if the form is filled in wrong.
Can someone please help?
Chris
$subst('Email.Unsub').
Message #4 by Russell Peto <russell.peto@i...> on Thu, 17 Jan 2002 15:43:05 -0000
|
|
Chris,
The trick to this is not to use a submit button on the form, rather use a
regular button that invokes a submit function, you can then put the form
validation in this function and only have it submit if the form fills the
required criteria.
E.G.
<script language="JavaScript">
function submitForm(){
var firstFieldValue = firstForm.firstField.value;
var secondFieldValue = firstForm.secondField.value;
if(firstFieldValue != ""){
if(secondFieldValue != ""){
firstForm.submit();
}
else{
alert("You must fill in both text boxes");
}
}
}
</script>
<form name="firstForm" method="post" action="processForm.asp">
First field <input type="text" name="firstField"><br>
Second field <input type="text" name="secondField"><br>
<input type="button" name="submitButton" value="Submit Form"
onClick="JavaScript:submitForm();">
</form>
hope this helps
Russell
-----Original Message-----
From: Christopher Cote [mailto:cotec@s...]
Sent: 17 January 2002 15:26
To: ASP Web HowTo
Subject: [asp_web_howto] Need help ASAP with form submit through
javascript function.
I have a form with javascript code to make sure that the form is filled in
correctly. If it isn't I don't want the form to go ahead submit. There
are 2 text boxes. If the user types text into one of them, he must input
something into the other one in order for it to work correctly. The other
option is to leave both text boxes blank. I can't figure out how to make
sure the form doesn't continue if the form is filled in wrong.
Can someone please help?
Chris
$subst('Email.Unsub').
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.314 / Virus Database: 175 - Release Date: 11/01/2002
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.314 / Virus Database: 175 - Release Date: 11/01/2002
Message #5 by "Drew, Ron" <RDrew@B...> on Thu, 17 Jan 2002 10:40:38 -0500
|
|
On the form statement add... onsubmit=3D"return CheckForm()"
The will execute your javascript and return a reply of true of false
Now in the Javascript put your checks...I added one for a name field
assuming you did multiple tests...
If false...it does not submit and returns to the location of focus on
the form.
<script language=3D"JavaScript">
<!--
function CheckForm() {
if (document.formmail.name.value =3D=3D "")
{
alert("Please enter a value for the \"Name\" field.");
document.formmail.name.focus();
return (false);
}
if (document.formmail.text1.value =3D=3D "" &
document.formmail.text2.value <> "")
{
alert("Please enter a value for the \"For Both Texts\" field.");
document.formmail.text1.focus();
return (false);
}
if (document.formmail.text1.value <> "" &
document.formmail.text2.value =3D=3D "")
{
alert("Please enter a value for the \"For Both Texts\" field.");
document.formmail.text2.focus();
return (false);
}
alert(" ..Thank you for completing the form. Your Information will be
sent when you close this window.");
}
//-->
</script>
-----Original Message-----
From: Christopher Cote [mailto:cotec@s...]
Sent: Thursday, January 17, 2002 10:26 AM
To: ASP Web HowTo
Subject: [asp_web_howto] Need help ASAP with form submit through
javascript function.
I have a form with javascript code to make sure that the form is filled
in
correctly. If it isn't I don't want the form to go ahead submit. There
are 2 text boxes. If the user types text into one of them, he must
input
something into the other one in order for it to work correctly. The
other
option is to leave both text boxes blank. I can't figure out how to
make
sure the form doesn't continue if the form is filled in wrong. Can
someone please help?
Chris
$subst('Email.Unsub').
|
|
 |