Window.location and form submission

L

Lukelrc

Hi,

I have a form containing (among other things) date fields for which i
have a date validation script. What i need to happen is when the user
presses the submit button the date validation script is run and only
if the date is correct is the form submited.

What i have done so far is:

-Chagned the button type from 'submit' to 'button'
-put the date validation vbscipt into a sub buttonname_onclick
-added to the date validation script code that says if the date is
valid then
window.location.href = "nextpage.asp"

it all works fine except that the new record added to the database
contains no values. It seems that the form does not submit properly
when i use window.location. Does anyone know to make a form submit
using window.location, or suggest another workaround?

Luke
 
R

Roland Hall

: Hi,
:
: I have a form containing (among other things) date fields for which i
: have a date validation script. What i need to happen is when the user
: presses the submit button the date validation script is run and only
: if the date is correct is the form submited.
:
: What i have done so far is:
:
: -Chagned the button type from 'submit' to 'button'
: -put the date validation vbscipt into a sub buttonname_onclick
: -added to the date validation script code that says if the date is
: valid then
: window.location.href = "nextpage.asp"
:
: it all works fine except that the new record added to the database
: contains no values. It seems that the form does not submit properly
: when i use window.location. Does anyone know to make a form submit
: using window.location, or suggest another workaround?

Hi Luke...

You need to submit your form. Set your action="nextpage.asp" and if the
validation passes, then use document.formname.submit();

Ex.

<script type="text/javascript">
function validate() {
var ename = document.form1.iname;
if(!ename.value) {
alert("Please input your email address");
ename.focus();
return false;
} else {
document.form1.submit();
return true;
}
}
</script>

<form id="form1" name="form1" action="nextpage.asp" onsubmit="return
validate()" />
<input type="text" id="iname" name="iname" value="" /><br />
<input type="submit" value="submit" />
</form>

FYI... This is not ASP related per se.

HTH...

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top