Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make div inline or visible problem

Status
Not open for further replies.
Apr 11, 2002
193
IN
Hi,

I have a hidden variable which is either set to 0 or 1. I have written a javascript function where i check if the hidden field value is 0 then make div display:none else make it inline. This javascript function is called on body onload. When onload is fired then the div becomes inline or none based on the condition but div's default style is inline so it is always visible. I am using ASP.net so first the body onload fires and then the div is rendered. If i call a javascript function on the onload of div then it gives me a error. Can this be handled in some other way.

Thanks,
Manish
 
Hi,

Here is the code.

function setVisible()
{

var isFlag=document.getElementById('hdnFlag'); //hidden field

if (isFlag.value == '1')
{
window.parent.frames('MainFrame').document.getElementById('Div1').style.display='inline';
}
else
{
window.parent.frames('MainFrame').document.getElementById('Div1').style.display='none';
}
}
function showTrades()
{

var isFlag=document.getElementById('hdnFlag'); //hidden field

if (isFlag.value == '0')
{
isFlag.value == '1';
window.parent.frames('MainFrame').document.getElementById('Div1').style.display='inline';

}
}


setVisible() is call on body onload and showTrades() is called on a click of a button.

<div id="Div1">
contains some tables
</div>

Thanks,
Manish
 
Wow, second time today (thread216-1403517)

You use double equals (==) to check for equality, single equals (=) assigns values. Your mistake is on this line:
Code:
function setVisible()
{
 
    var isFlag=document.getElementById('hdnFlag'); //hidden field
    
    if (isFlag.value == '1')
    {
        window.parent.frames('MainFrame').document.getElementById('Div1').style.display='inline';
    }
    else
    {
        window.parent.frames('MainFrame').document.getElementById('Div1').style.display='none';
    }        
}
function showTrades()
{

    var isFlag=document.getElementById('hdnFlag'); //hidden field

    if (isFlag.value == '0')
    {
        [!]isFlag.value == '1';[/!]
        window.parent.frames('MainFrame').document.getElementById('Div1').style.display='inline';

    }
}

Just out of curiosity, is the isFlag.value supposed to be assigned a value somewhere in the setVisible function?

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
 
Hi,

Thanks for the response. Yes, isFlag.value == '1'; was a error, but i am calling setVisible() on body onload and the default value of the hidden field is 0. It goes in the else and it makes the div none. But it is still visible.

setVisible() doesnt set value to the hidden field there are button on click of which the value is set. But when the page loads the div is visible which should not be.

Thanks,
Manish
 
It's hard to tell what you've got going on there since you haven't posted all the code for the page, or a link to the page. The best I can do is give you a working, bare-bones example and hopefully you can incorporate that into your code:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>title test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<script type="text/javascript">

var isVisible = false;

function switchVisibility() {
   var theDiv = document.getElementById("blah");
   theDiv.style.display = (isVisible) ? "block" : "none";
   isVisible = !isVisible;
}

window.onload = switchVisibility;

</script>

<style type="text/css">
</style>
</head>
<body>
   <div id="blah">
      blahblahblahblahblahblah<br />
      blahblahblahblahblahblahblah<br />
      blahblah
   </div>
   <input type="button" value="switch visibility" onclick="switchVisibility()" />
</body>
</html>

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
 
Hi,

Thanks for the reply. My issue was probably the Div was runat="server".

Manish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top