html radio button if checked - please specify

HTML, CSS and anything else that deals with client side capabilities.

Moderator: General Moderators

Post Reply
sectionLeader123
Forum Commoner
Posts: 31
Joined: Fri Oct 11, 2013 8:46 am

html radio button if checked - please specify

Post 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>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: html radio button if checked - please specify

Post by Celauran »

Sounds like a checkbox would suit better here than a radio button.
sectionLeader123
Forum Commoner
Posts: 31
Joined: Fri Oct 11, 2013 8:46 am

Re: html radio button if checked - please specify

Post by sectionLeader123 »

Actually I had it working with a drop down list but my employer requested that I use a radio button.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: html radio button if checked - please specify

Post 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.
sectionLeader123
Forum Commoner
Posts: 31
Joined: Fri Oct 11, 2013 8:46 am

Re: html radio button if checked - please specify

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: html radio button if checked - please specify

Post 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.
(#10850)
sectionLeader123
Forum Commoner
Posts: 31
Joined: Fri Oct 11, 2013 8:46 am

Re: html radio button if checked - please specify

Post by sectionLeader123 »

got it appreciate the input
Post Reply