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
274 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
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)

896 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

14 Experts available now in Live!

Get 1:1 Help Now