...

View Full Version : dynamic number of input fields??



Speedy
10-25-2003, 10:17 PM
Hi,

I wonder if there is a way to let the client
choose the number of inputs he/she wanna do?

For example, I'm trying to make a signup page where
a team can type in the number of players they
have to represent them in a golf tournament so if they
type in 6 in that field then there will be 6 fields
where to type there names for saving to a database.

If there is a way, how would the code for that specific
task look like??

/Speedy

raf
10-25-2003, 11:17 PM
You could do that, by submittingthe form after they typed in the number, and then dynamically build the form for the names. Suppose the first form has this field with name="ammount" . Then you would have


if CInt(request.form("ammount")) > 0 then ' so if they entered a number greater then 0
your code form the form
dim i
i = 1
do while i <= request.form("ammount")
response.write("Name of player " & i & " : " )
response.write("<input type=""text"" name=""player" & i & """ />")
i=i+1
loop
your other formcode
else
your code to redirect to the first form
end if


in the page where the form is posted to

glenngv
10-27-2003, 06:29 AM
or you can do it on the client-side through JavaScript and DOM

angiras
10-27-2003, 12:30 PM
I got this somewhere and never used it

-----------------

<!-- TWO STEPS TO INSTALL DYNAMIC INPUT:

1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->

<HEAD>


<script language="JavaScript">
<!--

function SymError()
{
return true;
}

window.onerror = SymError;

var SymRealWinOpen = window.open;

function SymWinOpen(url, name, attributes)
{
return (new Object());
}

window.open = SymWinOpen;

//-->
</script>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Peter Hermus -->
<!-- Web Site: http://come.to/speedpete -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function createForm(number) {
data = "";
inter = "'";
if (number < 16 && number > -1) {
for (i=1; i <= number; i++) {
if (i < 10) spaces=" ";
else spaces=" ";
data = data + "URL " + i + " :" + spaces
+ "<input type='text' size=10 name=" + inter
+ "url" + i + inter + "'><br>";
}
if (document.layers) {
document.layers.cust.document.write(data);
document.layers.cust.document.close();
}
else {
if (document.all) {
cust.innerHTML = data;
}
}
}
else {
window.alert("Please select up to 15 entries.");
}
}
// End -->
</script>
</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

<BODY>

<center>
<form name=counter>
Number of URLs to enter:
<input type=text name=number size=5>
<input type=button value="Update" onClick="createForm(counter.number.value);">
</form>

<br>

<form name="webform">
<table border=0>
<tr valign=top>
<td>Name:</td>
<td><input type=text size=20 name=name onChange="msg(this.form)"></td>
</tr>

<tr><td colspan=2>

<!-- Placeholder for dynamic form contents -->
<span id=cust style="position:relative;"></span>

</td>
</tr>

<tr valign=top>
<td>Comments:</td>
<td><textarea name=comments cols=45 rows=5 wrap=virtual OnChange="msg(this.form)">
</textarea></td>
</tr>
<tr>
<td></td>
<td><input type=submit value="Send"></td>
</tr>
</table>
</form>
</center>

<p><center>
<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size: 1.95 KB -->



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum