Hi all,
I have a form which has two radio buttons at the beginning which show and hide fields depending on what button is clicked:
I want to adapt this js and html code so that when the page loads it checks whether one of the two radio buttons is clicked and depending on that it displays/hides the divs which are declared in the current function, at the moment it performs this when the user clicks one of the radio buttons but I want to perform it when the page is loaded and also when the user first enters the page I want the yes radio button to be selected and obviously show/hide the appropriate fields.
Thanks for the help!
function checkjob(jobvalue){
if(jobvalue!="yes") {
document.getElementById("nombre").style.display = "block";
document.getElementById("apellido").style.display = "block";
document.getElementById("empresa").style.display = "none";
document.getElementById("contacto").style.display = "none";
}else{
document.getElementById("nombre").style.display = "none";
document.getElementById("apellido").style.display = "none";
document.getElementById("empresa").style.display = "block";
document.getElementById("contacto").style.display = "block";
}
}
HTML
<div class="form_element">
<label >></label>
<div class="radio_element">
<input type="radio" value="yes" class="radio" id="yes" name="job" onchange="checkjob(this.value)" >
<span >yes</span>
</div>
<div class="radio_element">
<input type="radio" value="no" class="radio" id="no" name="job" onchange="checkjob(this.value)">
<span >no</span>
</div>
</div>