Select inside a form

Discussion in 'Javascript' started by Leszek, Dec 28, 2005.

  1. Leszek

    Leszek Guest

    function zmiana(ile){
    var formObj = document.getElementById("dane").
    while(formObj.childNodes.length > 3)
    {
    formObj.removeChild(formObj.lastChild);
    }
    for (i=1;i<=ile;i++){
    pole=document.createElement("BR");
    formObj.appendChild(pole);

    a=document.createTextNode("Name of accompanying person #"+i+" ")
    formObj.appendChild(a);

    formObj.style.fontWeight='bold';

    pole=document.createElement("input");
    pole.type = "text";
    pole.size="40";
    pole.id="name"+i;
    pole.name="name"+i;
    formObj.appendChild(pole);
    }
    }

    What should be in changed in line:

    var formObj = document.getElementById("dane").

    to make it work with something like this

    <form name="dane">
    <select name="accomp">

    //instructions

    </select>
    </form>

    Thanks.
    Leszek
    Leszek, Dec 28, 2005
    #1
    1. Advertising

  2. Leszek wrote:

    > [...]


    You'll probably bite the carpet when you have read the reponses to your
    other posting because they address the problems with that code.

    > What should be in changed in line:
    >
    > var formObj = document.getElementById("dane").
    >
    > to make it work with something like this
    >
    > <form name="dane">


    Again, the `action' attribute is missing. The above is invalid HTML.

    > <select name="accomp">
    >
    > //instructions


    Again, HTML is not a programming language; it is a markup language.

    > </select>
    > </form>


    var formObj = document.forms["dane"];

    because there is no _ID_ `dane', there is a _name_.

    However, you should rather try to pass a reference to the HTMLSelectElement
    object (and then use its `form' property) or to the HTMLFormElement, with
    `this'.


    PointedEars
    Thomas 'PointedEars' Lahn, Dec 28, 2005
    #2
    1. Advertising

  3. Leszek

    Leszek Guest

    Uzytkownik "Thomas 'PointedEars' Lahn" <> napisal w
    wiadomosci news:...
    >
    > var formObj = document.forms["dane"];

    I tried with this and it works but the text inputs made by function are now
    outside frameset and below submit button
    Here is code again:

    function zmiana(ile){
    var formObj = document.forms["dane"];
    while(formObj.childNodes.length >3)
    {
    formObj.removeChild(formObj.lastChild);
    }
    for (i=1;i<=ile;i++){
    pole=document.createElement("BR");
    formObj.appendChild(pole);

    a=document.createTextNode("Name of accompanying person #"+i+" ")
    formObj.appendChild(a);

    formObj.elements.style.fontWeight='bold';

    pole=document.createElement("input");
    pole.type = "text";
    pole.size="40";
    pole.id="$name"+i;
    pole.name="$name"+i;
    formObj.appendChild(pole);
    }
    }

    <form name="dane" action="uzytkownik.php" method.post>
    <fieldset>

    <select name="accperson" onChange="zmiana(this.value)">
    <?php
    $accperson=0;
    echo "<option value=\"$accperson\" selected >$accperson</option> \n";
    for ($accperson=1;$accperson<=5;$accperson++){
    echo "<option value=\"$accperson\">$accperson </option>\n";
    }
    ?>
    </select>
    <p align="center">
    <input type="submit" value="Wyslij dane" />
    </p>
    </fieldset>
    </form0
    Leszek, Dec 28, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark
    Replies:
    2
    Views:
    6,049
  2. yawnmoth
    Replies:
    2
    Views:
    432
    Peter Flynn
    Aug 18, 2008
  3. cgplays.com
    Replies:
    1
    Views:
    101
    Pachydermitis
    Aug 16, 2003
  4. palmiere
    Replies:
    1
    Views:
    312
    Erwin Moller
    Feb 9, 2004
  5. Replies:
    4
    Views:
    227
    Thomas 'PointedEars' Lahn
    May 9, 2005
Loading...

Share This Page