Convert javascript for Firefox

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

    #1

    Convert javascript for Firefox

    Hi

    I use the following script in order to show/hide a section, and at the same
    time to change a companion .gif with another:

    function doExpand(paraNu m,arrowNum){
    if
    (paraNum.style. display=="none" ){paraNum.style .display="";arr owNum.src="../../images/arrOn.gif"}
    else {paraNum.style. display="none"; arrowNum.src=". ./../images/arrOff.gif"}
    }

    and then in the body:
    <div id="reltpc"><a href="javascrip t:;" onClick="doExpa nd(xplan1,ico1) "><img
    id="ico1" src="../../images/arrOff.gif" alt="" width="10" height="9"
    border="0"> Show Info</a></div>
    <div id="xplan" style="display: none" onClick="doExpa nd(xplan,ico1)" >
    <p>text here</p>
    <p>some more text here</p>
    </div>

    Furthermore, two more scripts are used in order to show/hide a section
    without the image:

    function doSection (secNum){
    if (secNum.style.d isplay=="none") {secNum.style.d isplay="block"}
    else{secNum.sty le.display="non e"}
    }

    function noSection (secNum){
    if (secNum.style.d isplay=="block" ){secNum.style. display="none"}
    }

    and then in the body:
    <div id="more"><a href="javascrip t:;" onClick="doSect ion(dtails1)">M ore
    Info</a></div>
    <div id="dtails1" style="display: none" onClick="noSect ion(dtails1)">
    <p>text here</p>
    <p>some more text here</p>
    </div>

    All three of them are working good in IE and Ffox, however the second claims
    to use "gelElementById " instead.

    Well, how could it be done? Would you help me please, to get that
    conversion?

    Thanks.

    --
    Merlin dying to the Lady of the Lake:
    "We lived our lives with passion and devotion"
    --
    Please, remove hyphens to contact me


  • Danny

    #2
    Re: Convert javascript for Firefox


    Keep it concise and precise, lots of wording, little specifc explanation,
    and the code looks very bloated, document.getEle mentById() is not
    mozilla/firefox, is DOM1 by the way and most browsers process it fine.

    Danny

    On Sun, 12 Jun 2005 10:43:42 -0700, geotso <kata-ye-xi@yahoo.gr> wrote:
    [color=blue]
    > Hi
    >
    > I use the following script in order to show/hide a section, and at the
    > same
    > time to change a companion .gif with another:
    >
    > function doExpand(paraNu m,arrowNum){
    > if
    > (paraNum.style. display=="none" ){paraNum.style .display="";arr owNum.src="../../images/arrOn.gif"}
    > else
    > {paraNum.style. display="none"; arrowNum.src=". ./../images/arrOff.gif"}
    > }
    >
    > and then in the body:
    > <div id="reltpc"><a href="javascrip t:;"
    > onClick="doExpa nd(xplan1,ico1) "><img
    > id="ico1" src="../../images/arrOff.gif" alt="" width="10" height="9"
    > border="0"> Show Info</a></div>
    > <div id="xplan" style="display: none" onClick="doExpa nd(xplan,ico1)" >
    > <p>text here</p>
    > <p>some more text here</p>
    > </div>
    >
    > Furthermore, two more scripts are used in order to show/hide a section
    > without the image:
    >
    > function doSection (secNum){
    > if (secNum.style.d isplay=="none") {secNum.style.d isplay="block"}
    > else{secNum.sty le.display="non e"}
    > }
    >
    > function noSection (secNum){
    > if (secNum.style.d isplay=="block" ){secNum.style. display="none"}
    > }
    >
    > and then in the body:
    > <div id="more"><a href="javascrip t:;" onClick="doSect ion(dtails1)">M ore
    > Info</a></div>
    > <div id="dtails1" style="display: none" onClick="noSect ion(dtails1)">
    > <p>text here</p>
    > <p>some more text here</p>
    > </div>
    >
    > All three of them are working good in IE and Ffox, however the second
    > claims
    > to use "gelElementById " instead.
    >
    > Well, how could it be done? Would you help me please, to get that
    > conversion?
    >
    > Thanks.
    >[/color]



    --
    Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

    Comment

    • RobG

      #3
      Re: Convert javascript for Firefox

      geotso wrote:[color=blue]
      > Hi
      >
      > I use the following script in order to show/hide a section, and at the same
      > time to change a companion .gif with another:
      >
      > function doExpand(paraNu m,arrowNum){
      > if
      > (paraNum.style. display=="none" ){paraNum.style .display="";arr owNum.src="../../images/arrOn.gif"}
      > else {paraNum.style. display="none"; arrowNum.src=". ./../images/arrOff.gif"}
      > }[/color]

      When posting code, please wrap manually at about 70 characters to
      stop auto-wrapping.
      [color=blue]
      >
      > and then in the body:
      > <div id="reltpc"><a href="javascrip t:;" onClick="doExpa nd(xplan1,ico1) "><img
      > id="ico1" src="../../images/arrOff.gif" alt="" width="10" height="9"
      > border="0"> Show Info</a></div>
      > <div id="xplan" style="display: none" onClick="doExpa nd(xplan,ico1)" >[/color]

      Here you are passing the id of the div 'xplan' to your function, then
      using it as a global variable. This is an Microsoft-ism - Firefox
      only supports it out of frustration that so many sites don't work if
      it doesn't. You are doing the same thing with 'ico1'.

      Since the onlcick is fired from the div that you are modifying, you
      can use 'this'. To get a reference to the image, you will need to
      use getElementById in your function, so the call is:

      <div id="xplan" style="display: none" onClick="doExpa nd(this,'ico1') ">

      And your function:

      function doExpand(paraNu m,arrowNum){
      var a = document.getEle mentByIt(arrowN um);
      if (paraNum.style. display == "none" ){
      paraNum.style.d isplay = "";
      arrowNum.src=". ./../images/arrOn.gif"
      }

      Read the group faq regarding support for getElementById for older
      browsers.

      <URL:http://www.jibbering.c om/faq/#FAQ4_15>


      --
      Rob

      Comment

      • RobG

        #4
        Re: Convert javascript for Firefox

        RobG wrote:
        [...][color=blue]
        >
        > Since the onlcick is fired from the div that you are modifying, you
        > can use 'this'. To get a reference to the image, you will need to
        > use getElementById in your function, so the call is:
        >
        > <div id="xplan" style="display: none" onClick="doExpa nd(this,'ico1') ">
        >
        > And your function:
        >
        > function doExpand(paraNu m,arrowNum){
        > var a = document.getEle mentByIt(arrowN um);[/color]

        Ooops, try:

        arrowNum = document.getEle mentById(arrowN um);
        [color=blue]
        > if (paraNum.style. display == "none" ){
        > paraNum.style.d isplay = "";
        > arrowNum.src=". ./../images/arrOn.gif"
        > }
        >[/color]


        --
        Rob

        Comment

        Working...