Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    May 2003
    Location
    Stockholm, Sweden
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    dynamic number of input fields??

    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

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Code:
    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

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    or you can do it on the client-side through JavaScript and DOM

  • #4
    Regular Coder
    Join Date
    Dec 2002
    Location
    France
    Posts
    522
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ..

    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 -->


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •