#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

    Javascript not working in firefox but worked fine in IE


    Hi friends i am using javascript which is working 100% fine in IE but not working in firefox..

    document.getElementById.style.visibility= hidden is not working in firefox.. I dont know why.. i searched a lot in google but no use..

    Here is my complete code ..




    <script language="javascript" type="text/javascript">
    function hide()
    {
    var elem = document.getElementById("brndname");

    if(elem.value == "SINEWAVE")
    {
    document.getElementById("exduty").style.visibility= "hidden";
    document.getElementById("cess").style.visibility = "hidden";
    document.getElementById("hecess").style.visibility = "hidden";
    }
    else
    {
    document.getElementById("exduty").style.visibility = "visible";
    document.getElementById("cess").style.visibility = "visible";
    document.getElementById("hecess").style.visibility = "visible";
    }
    }
    </script>

    <div class="field">
    <label for="Brand">Brand name:</label>
    <select name="brndname" onchange="hide()">
    <option value="LOGICSTAT">LOGICSTAT</option>
    <option value="SINEWAVE">SINEWAVE</option>
    </select>
    </div>

    <div class="field">
    <label for="excise duty">Excise Duty:</label>
    <input style="width: 100px" type="number" class="input" name="exduty" id="exduty" maxlength="5" required />
    </div>
    <div class="field">
    <label for="Cess Charge">Cess Charge:</label>
    <input style="width: 100px" type="number" class="input" name="cess" id="cess" maxlength="5" required />
    </div>

    <div class="field">
    <label for="HECesscharge">H.E. Cess Charge:</label>
    <input style="width: 100px" type="number" class="input" name="hecess" id="hecess" maxlength="5" required />
    </div>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    50
    Rep Power
    35
    Looks like you're missing the id attribute on your select element:
    Code:
    <select name="brndname" onchange="hide()" id="brndname">
        <option value="LOGICSTAT">LOGICSTAT</option>
        <option value="SINEWAVE">SINEWAVE</option>
    </select>
    Working for me here on Chrome and Firefox: http://jsfiddle.net/rJ5aM/

    Comments on this post

    • Kravvitz agrees
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    2
    Rep Power
    0
    Originally Posted by Edge360
    Looks like you're missing the id attribute on your select element:
    Code:
    <select name="brndname" onchange="hide()" id="brndname">
        <option value="LOGICSTAT">LOGICSTAT</option>
        <option value="SINEWAVE">SINEWAVE</option>
    </select>
    Working for me here on Chrome and Firefox: http://jsfiddle.net/rJ5aM/

    Oh my god... what a shame full mistake by me...

    Thanks a lot buddy
  6. #4
  7. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,122
    Rep Power
    4258
    Welcome to DevShed Forums, rahul_22_99.

    That's a known bug in IE: Beware of id and name attribute mixups when using getElementById in Internet Explorer

    P.S. Please remember to change the value of the label's "for" attribute to match the <select> element's ID.
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).

IMN logo majestic logo threadwatch logo seochat tools logo