Solved

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

Posted on 2013-01-01
4
621 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 16

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

791 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