Problem: script works in IE but not FF

M

Martin

I have the javascript shown below in the <head> section of a web page.

In IE, both of these functions execute properly (they are both being
triggered by the onchange event in several different inputs)
However, in FF, the 2nd function does not execute. The "toggleState"
function works but "markChange" does not. To execise this, I added
an alert('It Works!') to the 2nd function - it pops up in IE but not
in FF.

Yes, javascript is enabled in FF. Like I said, the 1st function works
ok (along with some other functions that are in page. Only the
markChange function doesn't work. And, yes, I have verified that the
function name is spelled and capitalized correctly everywhere.

Any thoughts as to what I need to look for?

Thanks.

---------------------------------------------------------------------------------------------------
<script type='text/javascript'>

function toggleState(item){
x='ONOFF'+item.name.substring(3);
if(item.className == 'on') {
item.className='off';
item.value='OFF';
document.getElementById(x).value='COFF';
} else {
item.className='on';
item.value='ON';
document.getElementById(x).value='CON';
}
}

function markChange(fldNum){
x=document.all['CHANGED'].value;
document.all['CHANGED'].value = x.substring(0,fldNum-1) +'1'+
x.substring(fldNum);
}
</script>
 
M

Martin Honnen

Martin said:
I have the javascript shown below in the<head> section of a web page.

In IE, both of these functions execute properly (they are both being
triggered by the onchange event in several different inputs)
However, in FF, the 2nd function does not execute. The "toggleState"
function works but "markChange" does not. To execise this, I added
an alert('It Works!') to the 2nd function - it pops up in IE but not
in FF.

Yes, javascript is enabled in FF. Like I said, the 1st function works
ok (along with some other functions that are in page. Only the
markChange function doesn't work. And, yes, I have verified that the
function name is spelled and capitalized correctly everywhere.
function markChange(fldNum){
x=document.all['CHANGED'].value;
document.all['CHANGED'].value = x.substring(0,fldNum-1) +'1'+
x.substring(fldNum);
}

Well document.all originates from the IE/MSHTML-DOM and Firefox only
supports it in quirks mode I think.
Check the error console in Firefox, if nothing happens at all with the
function then it is likely to show you the reason.
 
M

Martin

Martin said:
I have the javascript shown below in the<head> section of a web page.

In IE, both of these functions execute properly (they are both being
triggered by the onchange event in several different inputs)
However, in FF, the 2nd function does not execute. The "toggleState"
function works but "markChange" does not. To execise this, I added
an alert('It Works!') to the 2nd function - it pops up in IE but not
in FF.

Yes, javascript is enabled in FF. Like I said, the 1st function works
ok (along with some other functions that are in page. Only the
markChange function doesn't work. And, yes, I have verified that the
function name is spelled and capitalized correctly everywhere.
function markChange(fldNum){
x=document.all['CHANGED'].value;
document.all['CHANGED'].value = x.substring(0,fldNum-1) +'1'+
x.substring(fldNum);
}

Well document.all originates from the IE/MSHTML-DOM and Firefox only
supports it in quirks mode I think.
Check the error console in Firefox, if nothing happens at all with the
function then it is likely to show you the reason.

Thanks, Martin.

The error console shows: document.all is undefined

Any suggestions as to how I can make this work?

This "CHANGED" field is a hidden input in which I'm setting a flag
(changing a 0 to a 1) that is used on the server side to control some
activity.

Thanks.
 
L

Luuk

Martin said:
I have the javascript shown below in the<head> section of a web page.

In IE, both of these functions execute properly (they are both being
triggered by the onchange event in several different inputs)
However, in FF, the 2nd function does not execute. The "toggleState"
function works but "markChange" does not. To execise this, I added
an alert('It Works!') to the 2nd function - it pops up in IE but not
in FF.

Yes, javascript is enabled in FF. Like I said, the 1st function works
ok (along with some other functions that are in page. Only the
markChange function doesn't work. And, yes, I have verified that the
function name is spelled and capitalized correctly everywhere.
function markChange(fldNum){
x=document.all['CHANGED'].value;
document.all['CHANGED'].value = x.substring(0,fldNum-1) +'1'+
x.substring(fldNum);
}

Well document.all originates from the IE/MSHTML-DOM and Firefox only
supports it in quirks mode I think.
Check the error console in Firefox, if nothing happens at all with the
function then it is likely to show you the reason.

Thanks, Martin.

The error console shows: document.all is undefined

Any suggestions as to how I can make this work?

This "CHANGED" field is a hidden input in which I'm setting a flag
(changing a 0 to a 1) that is used on the server side to control some
activity.

Thanks.

if your page looks like this:
<form name="From">
<input type="hidden"name="field">
</form>

Then this should work:
document.forms['From'].field.value = '1';
 
J

Jukka K. Korpela

The error console shows: document.all is undefined

Any suggestions as to how I can make this work?

For maximal interoperability, you might use document.getElementById when
it is defined and document.all otherwise (and give up, making horrible
noises, when neither is defined), but that would probably be overkill
nowadays - especially since other parts of your code assume that
document.getElementById is defined.
This "CHANGED" field is a hidden input in which I'm setting a flag
(changing a 0 to a 1) that is used on the server side to control some
activity.

The simplest way over this problem is to add id="CHANGED" (unless
"CHANGED" is already in use as an id value, in which case you need to
invent some other value that is not in use yet) to that field and use
document.getElementById("CHANGED").

This being said, it is inherently unsafe to rely on JavaScript for
tracking down changes. The server-side form handler should know the data
that was sent in the form and should then compare the data received
against that. Remember that users or systems may switch off JavaScript
and may use a modified version of your page, with modified markup and/or
JavaScript.
 
D

Dr J R Stockton

In comp.lang.javascript message <s6n2t6di3b5kmicvpcds7tt5napd0m5pm9@4ax.
In IE, both of these functions execute properly (they are both being
triggered by the onchange event in several different inputs)
However, in FF, the 2nd function does not execute. The "toggleState"
function works but "markChange" does not. To execise this, I added
an alert('It Works!') to the 2nd function - it pops up in IE but not
in FF.

function markChange(fldNum){
x=document.all['CHANGED'].value;
document.all['CHANGED'].value = x.substring(0,fldNum-1) +'1'+
x.substring(fldNum);
}

You have been told how to fix it.

Additionally, in that function there should be a 'var' before 'x=', and
the function could better have been written as something like

function markChange(fldNum) {
var x = document.all['CHANGED'], t = x.value
x.value = t.substring(0, fldNum-1) + '1' + t.substring(fldNum);
}


Personally, rather than accessing an element by using one of the global
collections accessed by a string representing name or ID, I would prefer
to use a more localised route to the element. For example, a button in
a form can be given onclick-"Func(this.form)" to call
function Func(F) { ... }
in which controls and other elements in the form can be addressed more
directly by using the argument F.

Global addressing may clash with something else on the page; local
addressing can at most clash locally.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top