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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show Panel

Status
Not open for further replies.

mchoudhury

Programmer
Nov 26, 2004
71
GB
Hi Guys,
I have a panel - inside the panel i have things like labels, textboxes etc. What i want is to write a JS OnClick event where if a checkbox is selected themn the panel will show up, and if the checkbox is de-selected then the panel will dissaper.
Can someone help me on how i could do that:

<asp:CheckBox ID="bill" Runat="server" onClick="document.getElementById('BillAddress').style.display=(this.Checked == True)?'inline':'none';"></asp:CheckBox>

Thanks
Mac
 
Can't use [blue]runat=server[/blue]


Code:
<input type=checkbox onClick="document.getElementById('BillAddress').style.display = this.checked ? 'inline' : 'none'; ">


Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook

 
I don't know why, but I have had bad results checking the value of .style.display. I tested every way I could think of, and regardless of the value that DISPLAYED for style.display, any expression testing it's value ALWAYS evaluted as TRUE. Bizarre, I know, but I'm not an amateur at this - I know what I saw. The only way I found to workaround it was to set a boolean flag to say whether the div was displayed or not. (This was in IE6). Strangely SETTING the value of style.display worked just like it was supposed to, only TESTING it did not. I am assuming there is a bug in it's toString or valueOf property, but either way, I'm not trusting it again - I'll keep track of display/non-display status on my own.

Meddle not in the affairs of dragons,
for you are crunchy, and good with mustard.
 
you might find that style.display will return "" the first time the code is run


Code:
<script language=javascript>
	function showDisplayStyle(inObj){
		alert(inObj.style.display)
		inObj.style.display = inObj.style.display == "none" ? "block" : "none"
	}

</script>

<input type=button value="SHOW/HIDE" onClick="showDisplayStyle(document.getElementById('theID'))">
<div id="theID">Now you see me</div>


Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top