Problem: script works in IE but not FF

Discussion in 'Javascript' started by Martin, May 16, 2011.

  1. Martin

    Martin Guest

    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>
     
    Martin, May 16, 2011
    #1
    1. Advertising

  2. 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/
     
    Martin Honnen, May 16, 2011
    #2
    1. Advertising

  3. Martin

    Martin Guest

    On Mon, 16 May 2011 19:27:20 +0200, Martin Honnen <>
    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.
     
    Martin, May 16, 2011
    #3
  4. Martin

    Luuk Guest

    On 16-05-2011 20:31, Martin wrote:
    > On Mon, 16 May 2011 19:27:20 +0200, Martin Honnen <>
    > 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
     
    Luuk, May 16, 2011
    #4
  5. 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/
     
    Jukka K. Korpela, May 16, 2011
    #5
  6. In comp.lang.javascript message <s6n2t6di3b5kmicvpcds7tt5napd0m5pm9@4ax.
    com>, Mon, 16 May 2011 10:23:10, Martin <>
    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.
     
    Dr J R Stockton, May 17, 2011
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. F. GEIGER
    Replies:
    3
    Views:
    792
    F. GEIGER
    Aug 6, 2004
  2. David Wang
    Replies:
    0
    Views:
    744
    David Wang
    Dec 1, 2006
  3. jefm
    Replies:
    4
    Views:
    651
  4. Volker Schmid

    ASP-Script works on W2000, but not on W2003?

    Volker Schmid, Nov 19, 2005, in forum: ASP General
    Replies:
    0
    Views:
    100
    Volker Schmid
    Nov 19, 2005
  5. Xeno Campanoli
    Replies:
    0
    Views:
    106
    Xeno Campanoli
    May 28, 2008
Loading...

Share This Page