waynew Posted March 8, 2009 Share Posted March 8, 2009 Hi, I have the following JS to hide and show a specific div on a contact form. It works in Firefox, but unfortunately; it fails to do anything in IE7. The functions are called when the user clicks on a specific list item. Any help would be greatly appreciated. // JavaScript Document var browserType; if (document.layers) {browserType = "nn4"} if (document.all) {browserType = "ie"} if (window.navigator.userAgent.toLowerCase().match("gecko")) { browserType= "gecko" } function hide() { if (browserType == "gecko" ) document.poppedLayer = eval('document.getElementById("secondborrowerdiv")'); else if (browserType == "ie") document.poppedLayer = eval('document.getElementById("secondborrowerdiv")'); else document.poppedLayer = eval('document.layers["secondborrowerdiv"]'); document.poppedLayer.style.visibility = "hidden"; } function show() { if (browserType == "gecko" ) document.poppedLayer = eval('document.getElementById("secondborrowerdiv")'); else if (browserType == "ie") document.poppedLayer = eval('document.getElementById("secondborrowerdiv")'); else document.poppedLayer = eval('document.layers["secondborrowerdiv"]'); document.poppedLayer.style.visibility = "visible"; } Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted March 8, 2009 Share Posted March 8, 2009 I think thats because the "visibility" attribute doesn't work that well in ie try changing visibility:hidden to display:none Quote Link to comment Share on other sites More sharing options...
waynew Posted March 8, 2009 Author Share Posted March 8, 2009 Hi, thanks for the reply. I tried that but unfortunately there's not a sign of life in IE7. Works perfectly in FF2. // JavaScript Document var browserType; if (document.layers) {browserType = "nn4"} if (document.all) {browserType = "ie"} if (window.navigator.userAgent.toLowerCase().match("gecko")) { browserType= "gecko" } function hide() { if (browserType == "gecko" ) document.poppedLayer = eval('document.getElementById("secondborrowerdiv")'); else if (browserType == "ie") document.poppedLayer = eval('document.getElementById("secondborrowerdiv")'); else document.poppedLayer = eval('document.layers["secondborrowerdiv"]'); document.poppedLayer.style.display = "none"; } function show() { if (browserType == "gecko" ) document.poppedLayer = eval('document.getElementById("secondborrowerdiv")'); else if (browserType == "ie") document.poppedLayer = eval('document.getElementById("secondborrowerdiv")'); else document.poppedLayer = eval('document.layers["secondborrowerdiv"]'); document.poppedLayer.style.display = "block"; } Quote Link to comment Share on other sites More sharing options...
waynew Posted March 8, 2009 Author Share Posted March 8, 2009 Btw, here's my HTML: <select class="border" id="life" name="life" title="Please select Single Life or Joint Life" size="1"> <option selected="selected" value="" onClick="showdiv('secondborrowerdiv)">-</option> <option value="single" onClick="hidediv('secondborrowerdiv)">Single Life</option> <option value="joint" onClick="showdiv('secondborrowerdiv)">Joint Life</option> </select> Please note that my JS now looks like: function hidediv(id) {document.getElementById(id).style.display = 'none';} function showdiv(id) {document.getElementById(id).style.display = 'block';} And that it works in FF. Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted March 8, 2009 Share Posted March 8, 2009 ie doens't like using onclick on a select element. use onchange instead <script> function changeVisibility(id,value){ if(value=="single"){ document.getElementById(id).style.display = 'block'; }else{ document.getElementById(id).style.display = 'none'; } } </script> <body> <select onchange="changeVisibility('secondborrowerdiv',this.value)" class="border" id="life" name="life" title="Please select Single Life or Joint Life" size="1"> <option selected="selected" value="" onClick="showdiv('secondborrowerdiv)">-</option> <option value="single">Single Life</option> <option value="joint">Joint Life</option> </select> Quote Link to comment Share on other sites More sharing options...
waynew Posted March 8, 2009 Author Share Posted March 8, 2009 I had a feeling that could have been the problem! Thanks a million! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.