Results 1 to 3 of 3

Thread: Added text boxes dynamically

  1. #1
    Join Date
    Jul 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Added text boxes dynamically

    I have a table in which users can enter up to 10 zip codes. Right now, I have 10 individual text boxes where they can enter the zips. However, as you can imagine, it looks a bit klunky. I'd like to be able to have a single text box with a text field somewhere nearby (either above or below probably) and have it so that when the user adds text in the box and click a button the text that was entered is placed in the field.
    I just can't remember how to do this. Can someone please help me?


    Thank you,
    Chris Cote

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Text boxes? Text fields? There aren't any such things. I think you mean textarea and text input, respectively. Do you?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Something like this:
    Code:
      <script type="text/javascript">
        var zipForm;
        function isZIP(s) {
          return /^\d{5}(-\d{4})?$/.test(s);
        }
      </script>
    </head>
    <body>
      <form action="/cgi-bin/processor" method="post">
       <div></div>
        <script type="text/javascript">
          zipForm = document.forms[document.forms.length - 1];
          zipForm.zipDiv = (zipForm.zipDiv = document.getElementsByTagName("div"))[zipForm.zipDiv.length - 1];
        </script>
        <input type="text" name="nextZip">
        <input type="button" onclick="
          var f = this.form,
            z = f.elements['nextZip'].value;
          if(!isZIP(z))
            return alert('Invalid ZIP code.');
          var d = document.createElement('div'),
            h = document.createElement('input');
          h.type = 'hidden';
          h.name = 'zip[]'; // [] for PHP and its poor support of the CGI standard.
          d.appendChild(document.createTextNode(z));
          d.appendChild(h).value = z;
          f.zipDiv.appendChild(d);
        ">
      </form>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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