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
279 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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
 

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Coldfusion / Railo 4 -  datetimeFormat problem 3 31
Passport Expiry 3 58
jQuery for Each 12 34
Need help with jQuery elements filtering 2 12
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ā€¦
This article discusses how to create an extensible mechanism for linked drop downs.
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)

789 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