Solved

ColdFusion How to disable "All" in Drop down when radio button is selected

Posted on 2013-01-01
4
608 Views
Last Modified: 2013-01-03
How can I disable "All" in my drop down when the user selects a radio button in a query?

I.E. Make the user select an option in the drop down, when a radio button is selected.

Radio code:
<input type="radio" name="showall" id="showall" value="1" />

Open in new window

     
Drop down code:
<select name="discipline1" style=width:170px;>
        <option value="ALL">ALL</option>
        <cfoutput query="DropDown1">
          <option value="#DropDown1.ship#">#DropDown1.ship#</option>
        </cfoutput>
    	</select>

Open in new window

0
Comment
Question by:DJPr0
  • 2
4 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 38735171
You could either go with jquery or use cfform's built in validation

Edit - Fix copy and paste error  

<!--- sample data for testing only --->
<cfset dropDown1  = queryNew("")>
<cfset queryAddColumn(DropDown1, "Ship", listToArray("AAA,BBB,CCC,DDD"))>

<script type="text/javascript">

	function validateDisipline1(frm, fld, listValue) {
		var buttonValue = getSelectedRadioButton("showall");
		var isOptional = buttonValue != "1";
		return isOptional || listValue.toLowerCase() != "all";
	}
	
	function getSelectedRadioButton(name) {
		var buttons = document.getElementsByName( name );
		for (var i = 0; i < buttons.length; i++) {
			if (buttons[i].checked) {
				return buttons[i].value;	
			}	
		}
		return "";
	}
</script>
<cfform method="post">
	<!--- Note, "ID" values must be unique --->
	<input type="radio" name="showall" value="1" /> Yes
	<input type="radio" name="showall" value="0" /> No

	<cfselect name="discipline1" id="discipline1" style="width:170px;" 
				onValidate="validateDisipline1"
				message="Please select a discipline value other than ALL">
        <option value="ALL">ALL</option>
        <cfoutput query="DropDown1">
          <option value="#DropDown1.ship#">#DropDown1.ship#</option>
        </cfoutput>
    </cfselect>
		
	<input type="submit">
</cfform>

Open in new window

0
 
LVL 15

Expert Comment

by:Gurpreet Singh Randhawa
ID: 38736078
with jquery you can do it like this:

$("#showall").click(function() {
      var i = $(this).val();
    alert(i);
     if (i == '1') {
         var selectAll = $("#discipline1 option:first").val();
         if ($.trim(selectAll) == 'ALL') {
            $("#discipline1 option:first").attr('disabled', true);
      }
     }
});¿

<input type="radio" name="showall" id="showall" value="1" />
<select name="discipline1" id="discipline1" style=width:170px;>
    <option value="ALL">ALL</option>
        <option value="2">2</option>
    <option value="3">3</option>
        </select>¿

Check this:

http://jsfiddle.net/NpNFh/6/
0
 
LVL 52

Expert Comment

by:_agx_
ID: 38736092

1.

Make the user select an option in the drop down, when a radio button is selected.

2.

How to disable "All" in Drop down when radio button is selected
Hm.. those are 2 different things.  Which one do you need? If it's 1, try my example. If it's 2, try myselfrandhawa's.
0
 

Author Closing Comment

by:DJPr0
ID: 38739712
Thanks _agx_ for sharing your knowledge.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now