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

Using onfocus in Netscape 4.0x 1

Status
Not open for further replies.

bcaunt

Technical User
Joined
Mar 2, 2004
Messages
6
Location
US
I am having a whale of time trying to figure out what is causing Netscape to not work with a piece of JavaScript; the same piece DOES work in IE, however. Here's what I have:

<input type=text onfocus="chkDonOffice()" name="email1" size="20" value="@abc.com">

(The above piece of code places the value '@abc.com' in a text field 'email1' with the assumption that the user will add their username in front of the '@' symbol. You'll note, though, that the function 'chkDonOffice' is called with an 'onfocus' event.)


function chkDonOffice()
{
if (document.forms[0].DonOff.value == "1030" || document.forms[0].DonOff.value == "1035")
{
document.forms[0].email1.value='newclient@abc.com'
return true;
}
}


(This piece of code above represents the function 'chkDonOffice'. If a previous field on the form - DonOff - was populated with either the value '1030' or '1035', the value of the 'email1' text area should be populated with 'newclient@abc.com'.)

As I mentioned earlier, this works well on IE, with no errors received. While an error is not received on Netscape, the desired action is not performed. Any thoughts?

Thanks!
Brent
 
try putting quotes around text

"Behind every great fortune there lies a great crime", Honore De Balzac
 
I followed bnymk's suggestion (replacing 'newclient@abc.com' with "newclient@abc.com"), and the problem still remains. What else could I try?

Brent
 
As bnymk said, try putting quotes around text.

If this doesn't happen, try some old-fashioned debugging by placing alert() in code. Is chkDonOffice() called at all? If true, debug value for DonOff etc.

Just curious... who is still using netscape 4?
 
Does NS4 even know what forms[0] is?

There's always a better way. The fun is trying to find it!
 
The quotes around text didn't help, so I did a debug with alert (). Here's my revised chkDonOffice function with the alerts inserted:

function chkDonOffice()
{
alert("Now starting chkDonOffice...");
if (document.forms[0].DonOff.value == "1030" || document.forms[0].DonOff.value == "1035")
{
alert("Value of DonOff is \"" + document.forms[0].DonOff.value + "\".");
document.forms[0].email1.value='poscnewclient@paychex.com'
alert("Value of email1 is \"" + document.forms[0].email1.value + "\".");
return true;
}
}


With IE, I got the three alert windows as expected, with happy results. With Netscape, though, the first alert window came up and kept repeating itself after each 'OK' click; I couldn't go any further into my debug process. Help! :-)
 
can you post the whole code that you have on the page so we can see???

"Behind every great fortune there lies a great crime", Honore De Balzac
 
and also try this

document.forms[formName].DonOff.value
instead of
document.forms[0].DonOff.value

and see where it gets you.

"Behind every great fortune there lies a great crime", Honore De Balzac
 

>> With Netscape, though, the first alert window came up and kept repeating itself after each 'OK' click;

This would be because the "onfocus" event would be firing each time you clicked "OK".

Try removing the line "return true;" - it doesn't appear to be neeeded.

Failing that, can you change the first alert to:

Code:
alert(document.forms[0].DonOff.value);

and see what is shown.

Hope this helps,
Dan

 
vongrunt, bnymk and BillRay...

Thanks for the help so far!

bnymk: replacing the "0" in 'forms[0]' with my form name did not correct the problem.

BillRay: Removing 'return true;' did not change the repeating alert window scenario. However, I did change the first 'alert' statement to reflect what you recommended, and the value being repeated to me was the word "null". When I run this debug on IE, the value returned to me is the correct value of "1030".

Here's the html:

<html>

<head>

<script language="JavaScript">

function chkDonOffice()
{
alert(document.forms[0].DonOff.value);
if (document.forms[0].DonOff.value == "1030" || document.forms[0].DonOff.value == "1035")
{
alert("Value of DonOff is \"" + document.forms[0].DonOff.value + "\".");
document.forms[0].email1.value='newclient@abc.com'
alert("Value of email1 is \"" + document.forms[0].email1.value + "\".");
return true;
}
}

function validator(theForm)
{
var rtn = true

if (rtn==true)
{
if (theForm.DonOff.selectedIndex == 0)
{
alert("Please select a donor office number!")
document.forms[0].DonOff.focus()
rtn=false
}
}

return rtn
}


</script>

</head>

<body onLoad="window.focus();">

<form method="POST" name="form1" onSubmit="return validator(this);" action="

<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td>Donor Office<br>
<select name="DonOff" size="1">
<option value="9999">Select a Donor Office</option>
<option value="0020">0020-Manhattan</option>
<option value="0026">0026-Philadelphia</option>
<option value="1030">1030-Online</option>
<option value="1035">1035-Online Plus</option>
</select>
</td>
<td>
Donor contact's e-mail address<br>
<input type="text" onfocus="chkDonOffice()" name="email1" size="20" value="@abcx.com">
</td>
</tr>
</table>

</form>

</body>

</html>


Thanks for your help!
Brent
 
I've just been reading up about the Level 0 DOM that Netscape 4 supported ( )... And the only difference I can see is the explicit use of the "elements" collection. So try changing your alert to this:

Code:
alert(document.forms[0].elements['DonOff'].value);

If that works, then making the same change to all other form element references should probably fix things.

Hope this helps,
Dan
 
Dan:

I applied that change to the chkDonOffice function, and received the same "null" value response that kept looping my alert window.

Still got my gears turning...
Brent
 

Got it... Although I had to install NN 4.08 to find it (and how obvious it appears with hindsight ;o)

The issue is that "DonOff" is a select box, and you should get the value of the select box the long-hand way for NN 4.08... So instead of "DonOff.value", you need to use "DonOff.options[DonOff.selectedIndex].value" (referencing the form too, of course).

If you modify your script to be as follows:

Code:
<script language="JavaScript">
<!--
function chkDonOffice() {
	var frm = document.forms[0].elements;
	var selValue = frm.DonOff.options[frm.DonOff.selectedIndex].value;
	if (selValue == "1030" || selValue == "1035") {
		frm.email1.value = 'newclient@abc.com';
		return (true);
	}
}

function validator(theForm) {
	var frm = document.forms[0].elements;
	if (frm.DonOff.selectedIndex == 0) {
		alert('Please select a donor office number!');
		frm.DonOff.focus();
		return (false);
	}
	return (true);
}
//-->
</script>

then all works as expected.

Hope this helps,
Dan
 
Dan:

That did it! I now have the functionality I'm looking for! Thanks so much for going the extra mile for me; I'm sure that working with Netscape 4.x must have sent shivers down your spine! :-)

Brent
 

It did indeed ;o)

The last time I worked with NN 4 was a good 2.5 years ago... So it was interesting to revisit it. I just can't believe that people are still using it, without realising the benefits of new browser technology.

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top