Forum Moderators: open

Message Too Old, No Replies

Javascript Code doesnot Work on Netscape

         

Madhur Tayal

8:22 am on Jul 22, 2004 (gmt 0)

10+ Year Member



The Follwoing javascript code doesnot works on Netscape but works fine on IE.

Can any one guide me, how it will work on Netscape

function validity()
{

elmt6=document.f1.spl_lname.value;
elmt7=document.f1.spl_name.value;

if (elmt6 == '')
{
alert('Last Name cannot be left blank..!');
document.f1.spl_lname.focus();
return false;
}

if (elmt7 == '')
{
alert('First Name cannot be left blank..!');
document.f1.spl_name.focus();
return false;
}
}

Span

9:53 am on Jul 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm no JS expert, but this should work in NN and IE:

function validity() {
if (document.f1.spl_lname.value.indexOf('')!=-1){
alert('Last Name cannot be left blank..!');
document.f1.spl_lname.focus();
return false;
}

StupidScript

4:22 pm on Jul 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's nice to see someone trusting so completely in Microsoft's programming! :) But it's not very forward-looking...

Instead of referring to the page element like:

document.f1.spl_lname

use a fully-qualified reference, like:

document.forms["f1"].elements["spl_lname"]

You are relying on Internet Explorer to assume it knows what you are referring to, under its "document.all" DOM...and that ain't right. Use a fully-qualified reference so that browsers that actually support the standard can respond, and IE will follow.