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

Javascript NOT working with Netscape!!?

Status
Not open for further replies.

Christiana

Technical User
Apr 24, 2001
21
0
0
CY
Hi you all!
I'm using this way to call a JScript function which validates the form.
<form action=&quot;add.asp&quot; method=&quot;post&quot; name=&quot;Add&quot; onsubmit=&quot;return Form_Validator(this)&quot;>

and here's the function

<script Language=&quot;JavaScript&quot;><!--
function Form_Validator(theForm)
{
if (theForm.Text1.selectedIndex == 0)
{ alert(&quot;The selection for Text is not valid.&quot;);
theForm.Text1.focus();
return (false);}
return (true);
}
//--></script>

It works fine with IE but not with Netscape. (I use Net. 6)
PLS HELP
Thanks in advance
 
the problem why your validation is not working is because you are not calling it properly.

you are saying:

if (theForm.Text1.selectedIndex == 0)
{ alert(&quot;The selection for Text is not valid.&quot;);
theForm.Text1.focus();
return (false);}
return (true);
butyour declaring the name of the form is &quot;Add&quot;
you are calling the wrong form.. try puttingthis in.

if (Add.Text1.selectedIndex == 0)
{ alert(&quot;The selection for Text is not valid.&quot;);
Add.Text1.focus();
return (false);}
return (true);
 
Actually it should work like it was originally posted because it's called with Form_Validator(this), so the theForm will be equal to...the form.

It works fine for me in Netscape 6...Here's the code I tested it with:
Code:
<html>
<head>
<script Language=&quot;JavaScript&quot;><!--
function Form_Validator(theForm)
{
alert(theForm)
  if (theForm.Text1.selectedIndex == 0)
  { alert(&quot;The selection for Text is not valid.&quot;);
    theForm.Text1.focus();
    return (false);}
  return (true);
}
//-->
</script>
</head>
<body>
<form action=&quot;add.asp&quot; method=&quot;post&quot; name=&quot;Add&quot; onsubmit=&quot;return Form_Validator(this)&quot;>
<select name=&quot;Text1&quot;>
<option></option>
<option>1</option>
<option>2</option>
</select>
<input type=&quot;submit&quot; value=&quot;submit&quot; />
</form>
</body>
</html>
 
hmmmm....... i had the same problem once before. the way that i solved it was by placing the call to the Form_Validator(this) withiin the <input type=&quot;submit&quot; value=&quot;submit&quot; />


by using the onclick event i was able to make it work by saying:


<input type=&quot;submit&quot; value=&quot;submit&quot; onclick=&quot;Form_Validator(this)/>


try it an see if it works or not ok
pelase let me know thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top