add controls dynamically in html

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ojvm

    add controls dynamically in html

    thanks in advance for reading this.
    i am a really ignorant about js, so i need a guru to help me.
    i need to add n number of text box in a html page, the main idea is
    when the user press a button apear 2 text box and if he do it again
    apear 2 text box more and so on, also need that all the text boxes has
    a unique id, in order to make some thing whit the values. but i dont
    know how to do it. please hel me i'm trapped in this

  • Danny

    #2
    Re: add controls dynamically in html


    May DOM be with you:




    function addboxes(n,_for m) {
    for (i=0;i<n;i++) {
    newBox=document .createElement( 'input');
    newBox.id='adde d_'+i;
    // and modify/add any other properties you wish here
    _form.appendChi ld(newBox);
    }



    <form onsubmit="retur n false">
    <input type="button" value="add more boxes"
    onclick="addbox es(5,this.form) ">
    </form>
    addboxes(HOWMAN YHERE, this.form); the one above adds 5


    Danny

    On Wed, 22 Jun 2005 09:22:44 -0700, ojvm <ojvm@productos mavi.com> wrote:
    [color=blue]
    > thanks in advance for reading this.
    > i am a really ignorant about js, so i need a guru to help me.
    > i need to add n number of text box in a html page, the main idea is
    > when the user press a button apear 2 text box and if he do it again
    > apear 2 text box more and so on, also need that all the text boxes has
    > a unique id, in order to make some thing whit the values. but i dont
    > know how to do it. please hel me i'm trapped in this
    >[/color]



    --
    Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

    Comment

    • ojvm

      #3
      Re: add controls dynamically in html

      thanks a lot this code worked fine.

      Comment

      Working...