Jump to content

Hide div


waynew

Recommended Posts

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";
}

Link to comment
https://forums.phpfreaks.com/topic/148474-hide-div/
Share on other sites

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";
}

Link to comment
https://forums.phpfreaks.com/topic/148474-hide-div/#findComment-779631
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/148474-hide-div/#findComment-779652
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/148474-hide-div/#findComment-779666
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.