Solved

want one select menu choice to change another select menu choice

Posted on 2013-05-28
4
359 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
Comment Utility
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
Comment Utility
0
 

Author Comment

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

Author Closing Comment

by:rgb192
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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)

744 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

8 Experts available now in Live!

Get 1:1 Help Now