Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

want one select menu choice to change another select menu choice

Posted on 2013-05-28
4
Medium Priority
?
386 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 1000 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 83

Assisted Solution

by:leakim971
leakim971 earned 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to dynamically set the form action using jQuery.
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)
Suggested Courses

885 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