Page 1 of 1

html radio button if checked - please specify

Posted: Thu Oct 17, 2013 7:36 am
by sectionLeader123
Hi, I have a radio button where I want to display a please specify textbox if the radio button is checked and if the radio button is unchecked again it goes away. Also at the moment I can uncheck the radio button through a reset button I have on the form I just use document.form.reset but is there anyway I can uncheck the radio button by simply clicking on it. Here is what I have so far:
Thanks

Code: Select all

<tr>
<td><label>Data Recovery Required?:
</label></td>
<input type="hidden" id="Datarec" name="dataRecYN" value="No"/>
<td>
<input type="radio" id="Datarec" name="dataRecYN" value="Yes"/>
<label id="dataspec" class="hide"><br/>Please Specify: <input type="text" name="txt"/></label></td>
</tr>

<script type="text/javascript">
document.getElementById('Datarec').onchange = function(e) {
var act = document.getElementById('dataspec');
	if(this !=checked)
	{
	   act.style.display = 'none';
	}
	else
	{
	   act.style.display = 'inline';
	}
}
</script>

Re: html radio button if checked - please specify

Posted: Thu Oct 17, 2013 9:37 am
by Celauran
Sounds like a checkbox would suit better here than a radio button.

Re: html radio button if checked - please specify

Posted: Thu Oct 17, 2013 10:52 am
by sectionLeader123
Actually I had it working with a drop down list but my employer requested that I use a radio button.

Re: html radio button if checked - please specify

Posted: Thu Oct 17, 2013 12:31 pm
by requinix
sectionLeader123 wrote:Actually I had it working with a drop down list but my employer requested that I use a radio button.
Push back. A radio button is the wrong element to use for something that can be selected and unselected. Users who want to uncheck it will try to click the button again (like if it were a checkbox) or try to find a different radio button to click (like a yes/no set). It's an unusual interface and users are stupid when it comes to unusual interfaces.

Speaking of, another option is making the No a radio button too. At least that way the user can switch between the two.

Re: html radio button if checked - please specify

Posted: Fri Oct 18, 2013 6:24 am
by sectionLeader123
The user requires me too have just the one radio button with a default value of 'No' so that if they don't select it then 'No' will get submitted to the database. Its just to save them time when entering a new record.

Re: html radio button if checked - please specify

Posted: Fri Oct 18, 2013 11:11 pm
by Christopher
You can set the default to 'No' for a select, radio or checkbox. That is not the reason to pick one. The have different functionality. With a radio you cannot uncheck it without checking another radio button in the same group. So for a single item a checkbox would be the right choice.

Re: html radio button if checked - please specify

Posted: Tue Oct 22, 2013 9:35 am
by sectionLeader123
got it appreciate the input