---HTML---
Do you own a Business?
<label><input type="radio" name="Business" value="Yes" id="Yes" onclick="showDiv('Biz');" /> Yes</label>
<label><input type="radio" name="Business" value="No" id="No" onclick="hideDiv('Biz');" />No</label>
<div id="Biz" style="display: none;">
What is the name of your Business?
<input>
</div>
---Javascript---
// Function to show div
function showDiv(divid){
if(document.getElementById(divid).style.display == 'none')
document.getElementById(divid).style.display = 'block';
}
// Function to hide div
function hideDiv(divid){
if(document.getElementById(divid).style.display == 'block')
document.getElementById(divid).style.display = 'none';
}
When you click yes your div element is displayed and when you click no it is hidden however, when the page is refreshed the div element becomes hidden again. Can anyone help me retain a visible div element if yes is clicked upon page refresh? Any help will be truly appreciated and I know this will be an easy fix for some of you pros.
Last edited by Benjamin on Thu May 07, 2009 11:51 am, edited 1 time in total.
Reason:Changed code type from text to html.
// Function to show div
function showDiv(divid){
if(document.getElementById(divid).style.display == 'none')
document.getElementById(divid).style.display = 'block';
}
// Function to hide div
function hideDiv(divid){
if(document.getElementById(divid).style.display == 'block')
document.getElementById(divid).style.display = 'none';
}
Last edited by Benjamin on Thu May 07, 2009 8:52 pm, edited 1 time in total.
Reason:Changed code type from text to javascript.
Inside the if() statement in your showdiv() function, call setcookie(), recording the fact that the div is shown.
Inside the if() statment in your hidediv() function, call setcookie(),recording the fact that the div is hidden.
When the page loads, read that cookie, and if it says the div is shown, then show the div. If it says the div is hidden, then hide the div.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.