Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

want one select menu choice to change another select menu choice

Posted on 2013-05-28
4
Medium Priority
?
381 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
[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 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 82

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
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 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

705 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