Solved

want one select menu choice to change another select menu choice

Posted on 2013-05-28
4
369 Views
Last Modified: 2013-05-29
<select name="choice1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<select>

if option 1 is selected then
<select name="choice2">
<option value="1">1</option>
</select>

if option 2 is selected then
<select name="choice2">
<option value="1">1</option>
<option value="2">2</option>
</select>

if option 3 is selected then
<select name="choice2">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
0
Comment
Question by:rgb192
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
Ahmed Hussein earned 250 total points
ID: 39202900
Here it is.

<script>
$(document).ready(function(){

	function changeValue(value){
		$("select[name='choice2']").html("");
		for(var i = 1; i <= value; i++){
			$("select[name='choice2']").append('<option value="'+i+'">'+i+'</option>');
		}
	}
	
	changeValue($("select[name='choice1']").val());
	$("select[name='choice1']").change(function(){
		changeValue($(this).val())
	});
});
</script>
<select name="choice1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<select>

<select name="choice2">

</select>

Open in new window


~AG
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 250 total points
ID: 39202901
0
 

Author Comment

by:rgb192
ID: 39206322
by: AhmedGeekPosted on 2013-05-28 at 17:38:31ID: 39202900
select name=choice1
does not populate choice2
0
 

Author Closing Comment

by:rgb192
ID: 39206331
both work with adding
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />

  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>

  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

slightly different code samples

thanks both
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

821 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