Solved

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

Posted on 2013-01-01
4
625 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 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