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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with form.submit()

Status
Not open for further replies.

wallgecko

Programmer
Dec 10, 2001
5
MY
I can't get this script to work, what went wrong?

<script>
function check(){
if(form1.textfield.value==&quot;&quot;){
alert(&quot;Fill it in&quot;);
}
else{
form1.submit();
}

}
</script>

<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;another.asp&quot;>
<input type=&quot;file&quot; name=&quot;file&quot;>
<input type=&quot;text&quot; name=&quot;textfield&quot;>
<input type=&quot;button&quot; name=&quot;Submit&quot; value=&quot;Submit&quot; onclick=&quot;check()&quot;>
</form>
 
try this instead

<script>
function check(){
if(form1.textfield.value==&quot;&quot;){
alert(&quot;Fill it in&quot;);
return false;
}
else
{
return true;
}

}
</script>

<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;another.asp&quot;>
<input type=&quot;file&quot; name=&quot;file&quot;>
<input type=&quot;text&quot; name=&quot;textfield&quot;>
<input type=&quot;button&quot; name=&quot;Submit&quot; value=&quot;Submit&quot; onclick=&quot;return check()&quot;>
</form>
 
actually change the button to this

<input type=&quot;Submit&quot; value=&quot;Submit&quot; onclick=&quot;return check()&quot;>
 
Actually, it doesn't work at all. In fact it even by passed the alert when I did not key in anything. Help?
 
A couple of possible problems:

onClick is supposed to be case sensitive. It may not be in all browsers, but that's the intention. Try it.

Try using document.formname.fieldname.value. That's the proper DOM way of referring to a field's value. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top