Solved

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

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

691 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