Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multipart Question

Status
Not open for further replies.

shamrox

Programmer
Sep 27, 2001
81
0
0
US
I have a webpage that I'd like to use to create a query on the fly with. I'm using php/mysql, but figure i need to some javascript to make this part happen.

1. I need something to create various number of dropdown boxes, the number would be defined each time by the user.
2. Once those drops appear, the value that was selected would then go into a textbox along with the other values, creating the string for the query.
3. When that is all done, they submit and the query gets run from the values that are in that last text box.

Possible? How?
Thanks in advance.

 
can you make a mockup to demonstrate what you want it to do?

-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
Here, i made a screen capture of the mockup page.


drops.bmp
 
still not quite sure how it should work, but something like this?
Code:
<!DOCTYPE HTML PUBLIC
	"-//W3C//DTD HTML 4.01 Transitional//EN"
	"[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
	<head>
		<title>test</title>
		<script type="text/javascript">
			function updateQuery(sel) {
				var query = sel.form.query;
				var sels = document.getElementsByName(sel.name);
				var vals = new Array();
				
				for (var x = 0; x < sels.length; x++) {
					if (sels[x].selectedIndex > 0) {
						vals.push(sels[x].options[sels[x].selectedIndex].value);
					}
				}
				
				query.value = vals.join(",");
			}
			
			function addSelect(form) {
				var container = document.getElementById("select-container");
				var div = document.createElement("div");
				var sel = document.createElement("select");
				var model = form.pubid.length ? form.pubid[0] : form.pubid;
				sel.setAttribute("name", "pubid");
				sel.onchange = function() { updateQuery(this); };
				
				for (var x = 0; x < model.options.length; x++) {
					sel.add( new Option(model.options[x].text, model.options[x].value), null );
				}
				
				div.appendChild(sel);
				container.appendChild(div);
			}
		</script>

	</head>

	<body>
		<form>
			<div>
			<input type="button" value="add another" onclick="addSelect(this.form);" />
			</div>
			
			<div id="select-container">
				<div>
				<select name="pubid" onchange="updateQuery(this);">
					<option value="-1">Please select a PubId</option>
					<option value="1">1</option>
					<option value="2">2</option>
					<option value="3">3</option>
					<option value="4">4</option>
					<option value="5">5</option>
				</select>
				</div>

				<div>
				<select name="pubid" onchange="updateQuery(this);">
					<option value="-1">Please select a PubId</option>
					<option value="1">1</option>
					<option value="2">2</option>
					<option value="3">3</option>
					<option value="4">4</option>
					<option value="5">5</option>
				</select>
				</div>

				<div>
				<select name="pubid" onchange="updateQuery(this);">
					<option value="-1">Please select a PubId</option>
					<option value="1">1</option>
					<option value="2">2</option>
					<option value="3">3</option>
					<option value="4">4</option>
					<option value="5">5</option>
				</select>
				</div>
			</div>
			
			<div>
			<textarea name="query" rows="5" cols="35"></textarea>
			</div>
			
		</form>
	</body>
</html>

-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top