Solved

How can I use jquery to auto create x amount of text fields below x amount of selections from a multiple list menu?

Posted on 2010-08-19
8
271 Views
Last Modified: 2012-05-10
Hi,

I have a list menu that is populated by our sales reps. I have a field below the list menu that the user can enter in a percent for the sale. However I need to make it so the list menu can select multiple sales reps and based on how many sales reps are selected I would like the same amount of text fields to populate below. Each one of the sales reps selected in the list menu should auto create the text fields with a sales rep assigned to each field (percent of sale).

Thank you,

Brian
<!--- B: get sales reps --->
			<cfinvoke 
				component = "cfc.salesReps" 
				returnvariable="qSalesReps"
				method="getSalesReps">
				</cfinvoke> 
				
				<select name="SalesReps" multiple="multiple">
					<cfoutput query="qSalesReps">
					<option value="#record_id#">#first_name# #last_name#</option>
					</cfoutput>
				</select>

<input type="text" name="sales_rep_id">

Open in new window

0
Comment
Question by:brihol44
  • 4
  • 4
8 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 33481218
Not fully understand but try this :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script language="javascript">
	$(document).ready(function() {
		$("option", "select[name='SalesReps']").click(function() {
			if( $(this).is(":selected") ) {
				for(var i=0;i<parseInt($("#sales_rep_id").val());i++) $("body").append("<br /><input type='text' name='" + $(this).val() +"' />");
			}
			else {
				$("input[name='" + $(this).val() + "']").remove();
			}
		});
	});
</script>
</head>
<body>
<select name="SalesReps" multiple="multiple"  size="8">
	<option value="record_id1">first_name1 last_name1</option>
	<option value="record_id2">first_name2 last_name2</option>
	<option value="record_id3">first_name3 last_name3</option>
	<option value="record_id4">first_name4 last_name4</option>
</select>
<br />
<input type="text" name="sales_rep_id" id="sales_rep_id" value="10">
<br />
</body>
</html>

Open in new window

0
 

Author Comment

by:brihol44
ID: 33486784
That's pretty close. I've attached a .PDF of what I need to make it easier. I don't think it's too much more than what you have done. I tried figuring it out from where you left off but I'm just a beginner at jQuery.

Brian
SalesRep.pdf
0
 

Author Comment

by:brihol44
ID: 33486873
Disregard the last .PDF... I made a instruction change that was more clear on this one.
SalesRep.pdf
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 33487185
try this :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script language="javascript">
	$(document).ready(function() {
		$("option", "select[name='SalesReps']").click(function() {
			$("option", "select[name='SalesReps']").each(function() {
				if( $(this).is(":selected") ) {
					//for(var i=0;i<parseInt($("#sales_rep_id").val());i++) 
					if($("input[name='" + $(this).val() + "']").length==0) $("body").append("<div><br />" + $(this).text() + "<input type='text' name='" + $(this).val() +"' /><div>");
				}
				else {
					$("input[name='" + $(this).val() + "']").parent().remove();
				}
			});
		});
	});
</script>
</head>
<body>
<select name="SalesReps" multiple="multiple"  size="8">
	<option value="record_id1">first_name1 last_name1</option>
	<option value="record_id2">first_name2 last_name2</option>
	<option value="record_id3">first_name3 last_name3</option>
	<option value="record_id4">first_name4 last_name4</option>
</select>
<br />
<input type="text" name="sales_rep_id" id="sales_rep_id" value="10">
<br />
</body>
</html>

Open in new window

0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:brihol44
ID: 33487275
Sweetness! Looks great! jQuery is so cool! Do you have any recommendations of books or other resources for learning jQuery? I'm ok at JavaScript. Would you recommend learning more JS first then getting into jQuery?

Thanks for the advice...
0
 

Author Closing Comment

by:brihol44
ID: 33487277
Nice job!
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33487355
>Would you recommend learning more JS first then getting into jQuery?

You can learn both at the same time but never forget the origin : Javascript
So 60/40

A book : I can't recommend you one, sorry
A good link(?) : http://www.noupe.com/tutorial/51-best-of-jquery-tutorials-and-examples.html
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33487360
Thanks for the points! Have a nice week-end!
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

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
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…

762 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

18 Experts available now in Live!

Get 1:1 Help Now