Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
need some regex help 15 27
CFFILE upload help 98 138
coldfusion, javascript onclick url update 4 45
Automate ColdFusion Internet Form with VBA from Access 10 36
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…
Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 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

22 Experts available now in Live!

Get 1:1 Help Now