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

Hide/Unhide div using Radio button onClick

Status
Not open for further replies.

malibu65k

Programmer
Sep 27, 2004
131
US
I've been trying this for days. JavaScript isn't even firing. Any Suggestions?? I'm using it with Coldfusion.

<script language="JavaScript" type="text/javascript">
function hide(divToHide) {
var me = document.getElementByID(divToHide);
if (me.style.display == "none"){
me.style.display = "block";
} else {
me.style.display = "none";
}
}
</script>


<div class = "col-md-12">
<h4>
<label class="radio-inline">
<input type="radio" value=1 name="decision" class="grey" onClick="hide('hideThis');">
<span style="color:red">Reject</span></label>
<label class="radio-inline">
<input type="radio" value=2 name="decision" class="grey" onClick="hide('hideThis');">
<span style="color:green">Approve</span></label>
</h4>
</div>


<div id="hideThis" style="display:none;">
<br>
<button class = "btn btn-blue btn-block" type = "submitAssign" name ="submitAssign" id = "submitAssign">
Assign <i class = "fa fa-arrow-circle-right" ></i>
</button>
</div>
 
Javascript is case sensitive. getElementById is different to getElementByID.

This should have popped up an error in the Js console of whatever browser you are using. Something like: Uncaught TypeError: document.getElementByID is not a function

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Still not working. No errors! Works in the Tryit Editor on the w3schools website. Just can't get it to work in my ColdFusion page.
 
hide('hideThis')


should be hide(this.id)

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
I found the issue after some removing and added back sections and pieces of code around the Radio buttons. The culprit was the class="grey" in <input type="radio" value=1 name="decision" class="grey" onClick="hide('hideThis');"> It was the onClick event that wasn't working because of that piece of code, the JavaScript was working fine. Works like a charm now.

Thanks to all anyway for the responses.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top