href not working in Netscape

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
noguru
Forum Commoner
Posts: 61
Joined: Thu Jun 06, 2002 4:03 am
Location: Just north of the City Of Gold, Land of Milk and Honey

href not working in Netscape

Post by noguru »

Hi,

This is working in Internet Explorer, but not in Netscape:

Code: Select all

function doNav(){
  alert('working!');
  location.href="options.php?id="+document.all.facultyid.value;
}
where facultyid is the name of an input field with type=text. I call the function on the click of a hyperlink. The alert is working, but not the href.

Any idea how I can change this to work in both IE and Netscape?

Thanks
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

It has to do with the differences in the DOM (Document Object Model), document.all does not exist in Netscape.

You may need to do something like

document.forms['myformname'].facultyid.value;

here is a sample of some code I have used in the past

var isIE4 = (document.all ? true : false);
var isNS4 = (document.layers ? true : false);
if (isNS4)
{
window.onLoad = function()
{
document.layers['apphead'].document.forms['myform'].searchname.focus();
}
}

if (isIE4)
{
window.onload = function ()
{
document.forms['myform'].searchname.focus();
}
}

This detects the browser type then references the objects in different ways, in addition the form was within a layer so added complication there

document.layers['layername'].document.forms['formname'].formitemname.focus();

In this case a form is on a document within a layer on the main document.

Hope this helps, you should also look up DOM in google and do a bit of reading.
User avatar
noguru
Forum Commoner
Posts: 61
Joined: Thu Jun 06, 2002 4:03 am
Location: Just north of the City Of Gold, Land of Milk and Honey

Post by noguru »

thanx mike, i'll try that.
Post Reply