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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

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

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
brihol44
Asked:
brihol44
  • 4
  • 4
1 Solution
 
leakim971PluritechnicianCommented:
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
 
brihol44Author Commented:
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
 
brihol44Author Commented:
Disregard the last .PDF... I made a instruction change that was more clear on this one.
SalesRep.pdf
0
Independent Software Vendors: 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!

 
leakim971PluritechnicianCommented:
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
 
brihol44Author Commented:
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
 
brihol44Author Commented:
Nice job!
0
 
leakim971PluritechnicianCommented:
>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
 
leakim971PluritechnicianCommented:
Thanks for the points! Have a nice week-end!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now