?
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
Medium Priority
?
290 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 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

RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

Question has a verified solution.

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

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
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…
Suggested Courses

800 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