Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Problem: script works in IE but not FF

Reply
Thread Tools

Problem: script works in IE but not FF

 
 
Martin
Guest
Posts: n/a
 
      05-16-2011
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>


 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      05-16-2011
Martin wrote:
> 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.





--

Martin Honnen
http://msmvps.com/blogs/martin_honnen/
 
Reply With Quote
 
 
 
 
Martin
Guest
Posts: n/a
 
      05-16-2011
On Mon, 16 May 2011 19:27:20 +0200, Martin Honnen <(E-Mail Removed)>
wrote:

>Martin wrote:
>> 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.
 
Reply With Quote
 
Luuk
Guest
Posts: n/a
 
      05-16-2011
On 16-05-2011 20:31, Martin wrote:
> On Mon, 16 May 2011 19:27:20 +0200, Martin Honnen <(E-Mail Removed)>
> wrote:
>
>> Martin wrote:
>>> 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';


--
Luuk
 
Reply With Quote
 
Jukka K. Korpela
Guest
Posts: n/a
 
      05-16-2011
16.5.2011 21:31, Martin wrote:

> 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.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
 
Reply With Quote
 
Dr J R Stockton
Guest
Posts: n/a
 
      05-17-2011
In comp.lang.javascript message <s6n2t6di3b5kmicvpcds7tt5napd0m5pm9@4ax.
com>, Mon, 16 May 2011 10:23:10, Martin <(E-Mail Removed)>
posted:

>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.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Website <http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc. : <http://www.merlyn.demon.co.uk/programs/> - see in 00index.htm
Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
import wx works interactive but not from script jefm Python 4 02-11-2009 09:24 AM
Re: same DLL (ASP.NET), but include only works for aspx but not fo David Wang ASP .Net 0 12-01-2006 01:42 AM
When I turn on my PC, it works, works, works. Problem! Fogar Computer Information 1 01-17-2006 12:57 AM
[py2exe.i18n] English works, German works, but not French. What do I miss? F. GEIGER Python 3 08-06-2004 10:01 AM
After rebooting my PC works, works, works! Antivirus problem? Adriano Computer Information 1 12-15-2003 05:30 AM



Advertisments