PDA

View Full Version : Netscape7 JavaScript conflicts with IE6 and Opera 7


Mark Phillips
06-17-2005, 08:51 PM
Hi,

I am writing an ASP.NET page that uses JavaScript to show, hide and set default values for a set of controls that are held in an array called the newExpenseControls. This code runs when the onchange event of a selectbox fires. The method works with no problem in IE6 and Opera7.02, but is not working in Netscape 7(Gecko). The event does seem to fire in Netscape 7 because the first method within the event is working. clearNewExpenseTextBoxes()

The code is pretty standard stuff. Can anyone help?

function newExpenseTypeChanged()
{
clearNewExpenseTextBoxes();

var expenseTypeID = newExpenseControls[0].options(newExpenseControls[0].selectedIndex).value;

// Set Qty
if (expenseTypeID == 1)// Telephone
{
newExpenseControls[3].style.visibility = "hidden";
setQtyValidators(false)
}
else
{
newExpenseControls[3].style.visibility = "visible";
setQtyValidators(true)

// Other
if (expenseTypeID == 3)
newExpenseControls[3].value = "1"
}

// Set Mileage
if (expenseTypeID == 2)
{
newExpenseControls[4].value = document.getElementById("hidMileageRate").value;
newExpenseControls[4].style.display="none";
setDisabledAmount(true);
}
else
{
setDisabledAmount(false);
newExpenseControls[4].style.display="inline";
}

newExpenseControls[1].focus();
}

nikkiH
06-17-2005, 08:59 PM
I think

var expenseTypeID = newExpenseControls[0].options(newExpenseControls[0].selectedIndex).value;

should be

var expenseTypeID = newExpenseControls[0].options[newExpenseControls[0].selectedIndex].value;

Did you check what the javascript console had? It shows errors there.

Mark Phillips
06-17-2005, 10:57 PM
Thanks for the help with the collection and the Console. Funny that IE would let that pass.

But now a new set of problems are arising in that same function. The newExpenseTypeChanged() function is calling:

function setQtyValidators(enable)
{
newExpenseValidators[4].enabled= enable;
newExpenseValidators[5].enabled= enable;
}

ASP.NET has validators that I am enabling and disabling. In IE6 this works fine. But I am getting the following error in NS7:

Error: newExpenseValidators[4] has no properties
Source File: http://localhost/FreelancerExtranet/js/expenses.js
Line: 119

How does a control have a property in one browser and not in another?

Thanks Again

Mark

nikkiH
06-18-2005, 03:00 AM
Different browsers have different DOM and they support custom stuff, too.
Get used to that. ;)

As to your error, global variables and scope are probably the issue.
MSIE will attempt to resolve names and references different than Gecko based browsers. It will look more expansively. Which can be good, but it can be bad, too, especially if you have name conflicts.

So, what is newExpenseValidators[4] pointing to?
And how are you expecting the browser to resolve the object? That is, you might be thinking it will look in one spot when it is actually doing something else.