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

Form validation works in IE not in NN

Status
Not open for further replies.

steve949

Programmer
Dec 6, 1999
1
US
Hi:<br>
I am using this code to validate a form on the page. It works with IE5 but not with Netscape. <br>
<br>
-----------------<br>
&lt;SCRIPT language=&quot;javascript&quot;&gt;<br>
&lt;!--<br>
function checknull() {<br>
if (info.fname.value == &quot;&quot;){<br>
alert(&quot;Please Enter Your First Name.&quot;);<br>
info.fname.focus();<br>
return false;<br>
}<br>
if (info.lname.value == &quot;&quot;){<br>
alert(&quot;Please Enter Your Last Name.&quot;);<br>
info.lname.focus();<br>
return false;<br>
}<br>
}<br>
--&gt;<br>
&lt;/SCRIPT&gt;<br>
<br>
&lt;!-- This is the form that calls it: --&gt;<br>
&lt;FORM name=info action=&quot;sb-1-userdata.asp?GO=true&cid=&lt;%=cid%&gt;&quot; method=POST onsubmit=&quot;return checknull()&quot;&gt;<br>
<br>
&lt;INPUT type=text name=&quot;fname&quot; maxlength=&quot;30&quot; size=30&gt;<br>
<br>
&lt;INPUT type=text name=&quot;lname&quot; maxlength=&quot;30&quot; size=30&gt;<br>
<br>
&lt;INPUT type=submit value=Proceed&gt;<br>
&lt;/FORM&gt;<br>
-----------------<br>
<br>
Any clues as to why this does not work in Netscape? It is the most basic validation! <br>
<br>
TIA<br>
<br>
Steve Jaeger<br>
<A HREF="mailto:steve@iconimage.com">steve@iconimage.com</A><br>
<A HREF=" TARGET="_new"><br>
 
Try this:<br>
<br>
&lt;SCRIPT language=&quot;javascript&quot;&gt;<br>
&lt;!-- <br>
function checknull(info) {<br>
if (info.fname.value == &quot;&quot;) {<br>
alert(&quot;Please Enter Your First Name.&quot;);<br>
info.fname.focus();<br>
return false;<br>
}<br>
if (info.lname.value == &quot;&quot;) {<br>
alert(&quot;Please Enter Your Last Name.&quot;);<br>
info.lname.focus();<br>
return false;<br>
}<br>
}<br>
//--&gt;<br>
&lt;/SCRIPT&gt;<br>
<br>
&lt;FORM name=info action=&quot;sb-1-userdata.asp?GO=true&cid=&lt;%=cid%&gt;&quot;<br>
method=POST onsubmit=&quot;return checknull(this)&quot;&gt;<br>
*<br>
*** send the form in<br>
...<br>
...<br>
...<br>
<br>
Either that or access the form through the document variable. document.info.fname.value<br>
<br>
tito<br>

 
<b>&lt;SCRIPT language=&quot;javascript&quot;&gt;<br>
&lt;!--<br>
function checknull()<br>
{<br>
&nbsp;if (document.info.fname.value == &quot;&quot;)<br>
&nbsp;{<br>
&nbsp;&nbsp;alert(&quot;Please Enter Your First Name.&quot;);<br>
&nbsp;&nbsp;document.info.fname.focus();<br>
&nbsp;&nbsp;return false;<br>
&nbsp;}<br>
&nbsp;if (document.info.lname.value == &quot;&quot;)<br>
&nbsp;{<br>
&nbsp;&nbsp;alert(&quot;Please Enter Your Last Name.&quot;);<br>
&nbsp;&nbsp;document.info.lname.focus();<br>
&nbsp;&nbsp;return false;<br>
&nbsp;}<br>
}<br>
;--&gt;<br>
&lt;/SCRIPT&gt;<br>
<br>
&lt;!-- This is the form that calls it: --&gt;<br>
&lt;FORM name=info action=&quot;sb-1-userdata.asp?GO=true&cid=&lt;%=cid%&gt;&quot; method=POST onsubmit=&quot;checknull()&quot;&gt;<br>
<br>
&lt;INPUT type=text name=&quot;fname&quot; maxlength=&quot;30&quot; size=30&gt;<br>
<br>
&lt;INPUT type=text name=&quot;lname&quot; maxlength=&quot;30&quot; size=30&gt;<br>
<br>
&lt;INPUT type=submit value=Proceed onclick=&quot;checknull();&quot;&gt;<br>
&lt;/FORM&gt;<br>
</b><br>
Here; I made several revisions to parts that my limited experience has taught me to be more dangerous shortcuts than the one Little Red Riding Hood took ;) Anywise; let me know if it still fails to function on either browser & I'll do some bug shooting of my own if it does....we'll <i>definately</i> find a way to get this script fixed up well for you. <p>-Robherc<br><a href=mailto:robherc@netzero.net>robherc@netzero.net</a><br><a href= > </a><br>*nix installation & program collector/reseller. Contact me if you think you've got one that I don't :)
 
You may need to add:<br>
<br>
info.lname.select()<br>
<br>
to the script. I've found that using focus isn't enough, you must also select it.<br>
<br>
-- Heidi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top