Javascript not working in firefox ??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • onlymars
    New Member
    • Mar 2008
    • 13

    Javascript not working in firefox ??

    here the code of a currency convertor i am using in my page which is not working in firefox but works in internet explorer.

    [code=javascript]<script language="javas cript" type="text/javascript">
    function convert()
    {
    var to, from;
    var to_rate, from_rate;
    var quantity, result;
    var temp;

    to=window.f1.se lect2.selectedI ndex;
    to_rate=window. f1.select2.opti ons[to].value;

    from=window.f1. select1.selecte dIndex;
    from_rate=windo w.f1.select1.op tions[from].value;

    quantity=window .f1.amount.valu e;

    if(quantity=="" )
    {
    window.alert("P lz specify any amount");
    window.f1.amoun t.focus();
    }
    else if(to==from)
    {
    alert("Please select different currencies");
    }
    else
    {
    temp=quantity/to_rate;
    result=temp*fro m_rate;
    window.f1.resul t.value=result;
    }
    }
    </script>
    [/code]

    you can also visite the page at www.malikexchan ge.com
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    use w3c-compliant dom-methods for ALL the references to document-nodes ... for example:

    [CODE=javascript]var my_form = document.getEle mentsByName('f1 ')[0];[/CODE]
    when you use that methods in nearly most cases you will not have any issues regarding such referencing problems between browsers ...

    kind regards

    Comment

    • onlymars
      New Member
      • Mar 2008
      • 13

      #3
      Thanx i visited the DOM objects and methods but i didn't understood a thing in it, can u plz just edit my code to work properly. ur support will be really appreciated.

      Comment

      • kunal pawar
        Contributor
        • Oct 2007
        • 297

        #4
        i suppose, this will help you
        <script language="javas cript" type="text/javascript">
        [CODE=javascript] function convert()
        {
        var to, from;
        var to_rate, from_rate;
        var quantity, result;
        var temp;

        to=document.get ElementById("se lect2").selecte dIndex;
        to_rate=documen t.getElementByI d("select2").op tions[to].value;

        from=document.g etElementById(" select1").selec tedIndex;
        from_rate=docum ent.getElementB yId("select1"). options[from].value;

        quantity=docume nt.getElementBy Id("amount").va lue;

        if(quantity=="" )
        {
        alert("Plz specify any amount");
        document.getEle mentByID("amoun t").focus();
        }
        else if(to==from)
        {
        alert("Please select different currencies");
        }
        else
        {
        temp=quantity/to_rate;
        result=temp*fro m_rate;
        document.getEle mentByID("resul t").value=resul t;
        }
        }[/CODE]
        </script>
        Last edited by acoder; Apr 9 '08, 03:04 PM. Reason: Added code tags

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          kunal, as a full member now, you should know that we expect your code to be posted in [CODE] tags (See How to Ask a Question).

          This makes it easier for everyone to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

          Please use the tags in future.

          MODERATOR.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by onlymars
            here the code of a currency convertor i am using in my page which is not working in firefox but works in internet explorer.
            Replacing window.f1 with document.f1 might be enough.

            [code=javascript]<script language="javas cript" type="text/javascript">
            function convert()
            {
            var to, from;
            var to_rate, from_rate;
            var quantity, result;
            var temp;

            to=document.f1. select2.selecte dIndex;
            to_rate=documen t.f1.select2.op tions[to].value;

            from=document.f 1.select1.selec tedIndex;
            from_rate=docum ent.f1.select1. options[from].value;

            quantity=docume nt.f1.amount.va lue;

            if(quantity=="" )
            {
            window.alert("P lz specify any amount");
            document..f1.am ount.focus();
            }
            else if(to==from)
            {
            alert("Please select different currencies");
            }
            else
            {
            temp=quantity/to_rate;
            result=temp*fro m_rate;
            document.f1.res ult.value=resul t;
            }
            }
            </script>
            [/code]

            Comment

            • kunal pawar
              Contributor
              • Oct 2007
              • 297

              #7
              sorry, i will take care next time

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Originally posted by kunal pawar
                sorry, i will take care next time
                Thanks !

                Comment

                Working...