Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forms Submission

Status
Not open for further replies.

ddchaos

Programmer
Joined
Nov 13, 2000
Messages
6
Location
US
I have messed with this script for too long. When I click on the link or on the button, I get a message that says "Object does not support this property or method." According to all the debuggers I've tried (Microsoft and Netscape) the code always fails at 'frm.submit()' I have tried different script placements, in line scripts etc. all to no avail. The only time this seems to work is if I don't do any validation. The only problem is, I'm working the issue for an on line job application where validate is absolutely imperitive.

Any ideas?

Thanks in advance

Paul

<HTML>
<HEAD>

<SCRIPT LANGUAGE=&quot;javascript&quot;>
<!--//
function submitIt(frm){
if(validate(frm) doSubmit(frm)
}

function doSubmit(frm){
frm.submit()
}

function validate(frm){
if(isEmpty(frm.fname.value) || isEmpty(frm.lname.value)){
alert(&quot;Please fill out form completely.&quot;);
return false;
}
return true;
}

function isEmpty(s){
if(s.length == 0 || s == &quot;&quot;){
return true;
}
}

//-->
</SCRIPT>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
</HEAD>

<BODY>

<!-- Border table -->
<FORM NAME=&quot;frmInput&quot; METHOD=&quot;post&quot; ACTION=&quot;output.asp&quot;>
<TABLE BORDER=0 CELLPADDING=1 CELLSPACING=0 BGCOLOR=&quot;#000000&quot;> <TR>
<TD>
<!-- Interior table -->
<TABLE BORDER=0 CELLPADDING=8 CELLSPACING=0 BGCOLOR=&quot;#BABABA&quot;>
<TR>
<TD>
<FONT FACE=&quot;verdana&quot; SIZE=3>
First Name
</TD>
<TD>
<INPUT NAME=&quot;fname&quot; TYPE=&quot;text&quot;>
</TD>
</TR>
<TR>
<TD>
<FONT FACE=&quot;verdana&quot; SIZE=3>
Last Name
</TD>
<TD>
<INPUT NAME=&quot;lname&quot; TYPE=&quot;text&quot;>
</TD>
</TR>
<TR>
<TD COLSPAN=2 ALIGN=right>
<FONT FACE=&quot;verdana&quot; SIZE=3>
<A HREF=&quot;javascript:submitIt(document.frmInput)&quot;>
Submit</A>
<P>
<INPUT NAME=&quot;submit&quot; TYPE=&quot;button&quot; VALUE=&quot;Submit&quot;
onClick=&quot;submitIt(document.frmInput)&quot;>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</FORM>


</BODY>
</HTML>
 
You can make things easier on yourself by using the onSubmit() handler in the <form> tag. Just remember to end your javascript function with a return true. Something akin to this:

<HTML>
<HEAD>
<SCRIPT LANGUAGE=&quot;javascript&quot;>
<!--//

function isEmpty(s){
if(s.length == 0 || s == &quot;&quot;){
return true;
}
}

function validate(frm){
if(isEmpty(frm.fname.value) || isEmpty(frm.lname.value)) {
alert(&quot;Please fill out form completely.&quot;);
return false;
}
return true;
}

//-->
</SCRIPT>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
</HEAD>
<BODY>
<!-- Border table -->
<FORM NAME=&quot;frmInput&quot; METHOD=&quot;get&quot; ACTION=&quot;test.html&quot; onSubmit='return validate(this);'>
<TABLE BORDER=0 CELLPADDING=1 CELLSPACING=0 BGCOLOR=&quot;#000000&quot;> <TR>
<TD>
<!-- Interior table -->
<TABLE BORDER=0 CELLPADDING=8 CELLSPACING=0 BGCOLOR=&quot;#BABABA&quot;>
<TR>
<TD>
<FONT FACE=&quot;verdana&quot; SIZE=3>
First Name
</TD>
<TD>
<INPUT NAME=&quot;fname&quot; TYPE=&quot;text&quot;>
</TD>
</TR>
<TR>
<TD>
<FONT FACE=&quot;verdana&quot; SIZE=3>
Last Name
</TD>
<TD>
<INPUT NAME=&quot;lname&quot; TYPE=&quot;text&quot;>
</TD>
</TR>
<TR>
<TD COLSPAN=2 ALIGN=right>
<INPUT TYPE=&quot;submit&quot; VALUE=&quot;Submit&quot;>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
 
Note that the few changes in the <form> tag (other than the onSubmit() entry) were things that I used to test the functionality of the page. It's not necessary to use the get method, and the action is completely irrelevent.

brendanc@icehouse.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top