getElementById ignored by Firefox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • GarryJones

    getElementById ignored by Firefox

    The following works in MSIE but not firefox.

    I suspect it has something to do with the fact that the element I am
    trying to access is not the "tid" which is the name of the DIV that is
    passed to this javascript. The function is a "show/hide" for a form. I
    want to ensure that any possible previously entered value is cleared
    so the user starts with an empty field with focus.

    I have tried to ways, with naming and getElementById but in both
    cases any entry is left standing and the focus is not passed in
    firefox, whilst both work fine in MSIE.

    First attempt (with getElementById)

    function InsertContentsh owgruppanm(tid) {
    if( document.getEle mentById(tid).s tyle.display == "none") {
    document.getEle mentById(tid).s tyle.display = "block";
    document.getEle mentById("grant _ask").selected Index=0;
    document.getEle mentById("tavfn mkas").value="" ;
    document.getEle mentById("tavfn mkas").focus()
    }

    else {
    document.getEle mentById(tid).s tyle.display = "none";
    }
    }


    Second attempt (with name of form inserted)

    function InsertContentsh owgruppanm(tid) {
    if( document.getEle mentById(tid).s tyle.display == "none") {
    document.getEle mentById(tid).s tyle.display = "block";
    document.getEle mentById("grant _ask").selected Index=0;
    document.prel_s vlmst_grpcol.ta vfnmkas.focus()
    }
    else {
    document.getEle mentById(tid).s tyle.display = "none";
    }
    }


    So obvious question. Whats the syntax for firefox?



  • Gregor Kofler

    #2
    Re: getElementById ignored by Firefox

    GarryJones meinte:
    The following works in MSIE but not firefox.
    >
    I suspect it has something to do with the fact that the element I am
    trying to access is not the "tid" which is the name of the DIV that is
    passed to this javascript. The function is a "show/hide" for a form.
    [snip]

    DIVs don't have names. Forms and their elements have.

    Anyway, your "problem" has been asked and answered hundreds of times
    before. MSIE automatically (and wrongly) populates the id property of
    elements with the same value of the name property, hence you can access
    form elements with names via gEBI() - but only in IE. gEBI() needs
    explicitly set (unique) ids. Otherwise resort to getElementsByNa me() -
    note the plural.

    Gregor



    --
    http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
    http://web.gregorkofler.com ::: meine JS-Spielwiese
    http://www.image2d.com ::: Bildagentur für den alpinen Raum

    Comment

    • GarryJones

      #3
      Re: getElementById ignored by Firefox

      On 5 Sep, 23:13, Gregor Kofler <use...@gregork ofler.atwrote:
      GarryJones meinte:
      >
      The following works in MSIE but not firefox.
      DIVs don't have names. Forms and their elements have.
      Still no go I am afraid....

      Let me explain. The DIV has an ID and the first 2 rows of code either
      display or hide the DIV which is correctly called by its id. Now, in
      that DIV is a form. And on that form there are some elements which
      have names. When the user clicks the link which fires this code it is
      supposed to empty any previously entered value.

      What I want is for the form to start with focus in the tavfnmkas
      field. This field should be empty so any left over data from previous
      viewings should be cleaned out when the button is clicked and the DIV
      (with the form) toggles status "none" to status "block" and becomes
      visible.

      What these three "document.getEl ementsByName" lines should do is

      document.getEle mentsByName("gr ant_ask").selec tedIndex=0; //SHOULD set
      the selected option index to zero in a SELECT
      document.getEle mentsByName("ta vfnmkas").value =""; //SHOULD removed any
      previously entered data from the field tavfnmkas
      document.getEle mentsByName("ta vfnmkas").focus () //SHOULD place focus
      in the field tavfnmkas

      "None of the above" is the result of my competence and understanding
      of this. I am very gratefull of any further help anyone would like to
      provide.

      My latest attempt using getElementsByNa me
      *************** *************** *************** **
      function InsertContentsh owgruppanm(tid) {
      if( document.getEle mentById(tid).s tyle.display == "none") {
      document.getEle mentById(tid).s tyle.display = "block";
      document.getEle mentsByName("gr ant_ask").selec tedIndex=0;
      document.getEle mentsByName("ta vfnmkas").value ="";
      document.getEle mentsByName("ta vfnmkas").focus ()
      }

      else {
      document.getEle mentById(tid).s tyle.display = "none";
      }
      }

      Any help appreciated!

      Garry Jones
      Sweden

      Comment

      • Gregor Kofler

        #4
        Re: getElementById ignored by Firefox

        GarryJones meinte:
        document.getEle mentsByName("gr ant_ask").selec tedIndex=0;
        document.getEle mentsByName("ta vfnmkas").value ="";
        document.getEle mentsByName("ta vfnmkas").focus ()
        getElementsByNa me() returns a collection (didn't I mention the plural?),
        therefore you need document.getEle mentsByName(".. .")[0].propertyOrMeth od.

        Gregor


        --
        http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
        http://web.gregorkofler.com ::: meine JS-Spielwiese
        http://www.image2d.com ::: Bildagentur für den alpinen Raum

        Comment

        Working...