how do i pass control(text field) values from one html to other using hidden variables.

Discussion in 'Javascript' started by prabodhtiwari@gmail.com, Mar 7, 2007.

  1. Guest

    function submitPartsForm(str) {

    var count=document.getElementsByName("partId");
    for(var i=0;i<count.length;i++)
    {

    document.mylist.myNum.value= document.getElementsByName("partNum")
    (i).value;

    }

    document.forms["mylist"].submit();
    }
    myNum[] is a hidden variable and partNum is the name of a text field
    that has many instances i mean there are many textfields with the same
    name so it forms a column in a data table.
     
    , Mar 7, 2007
    #1
    1. Advertising

  2. Erwin Moller Guest

    wrote:

    >
    > function submitPartsForm(str) {
    >
    > var count=document.getElementsByName("partId");
    > for(var i=0;i<count.length;i++)
    > {
    >
    > document.mylist.myNum.value= document.getElementsByName("partNum")
    > (i).value;
    >
    > }
    >
    > document.forms["mylist"].submit();
    > }
    > myNum[] is a hidden variable and partNum is the name of a text field
    > that has many instances i mean there are many textfields with the same
    > name so it forms a column in a data table.


    Why not give each each textfield a unique name?
    I cannot think of one good reason...

    Regards,
    Erwin Moller
     
    Erwin Moller, Mar 7, 2007
    #2
    1. Advertising

  3. Darko Guest

    On Mar 7, 12:14 pm, Erwin Moller
    <> wrote:
    > wrote:
    >
    > > function submitPartsForm(str) {

    >
    > > var count=document.getElementsByName("partId");
    > > for(var i=0;i<count.length;i++)
    > > {

    >
    > > document.mylist.myNum.value= document.getElementsByName("partNum")
    > > (i).value;

    >
    > > }

    >
    > > document.forms["mylist"].submit();
    > > }
    > > myNum[] is a hidden variable and partNum is the name of a text field
    > > that has many instances i mean there are many textfields with the same
    > > name so it forms a column in a data table.

    >
    > Why not give each each textfield a unique name?
    > I cannot think of one good reason...
    >
    > Regards,
    > Erwin Moller


    Try naming them as follows:
    <input name="partnum[]" ...>
    In PHP, these are automatically converted into an array inside your
    protocol-dependent superglobal (_GET or _POST), so you can use them at
    will, although, if this is a static html, why not really give them all
    unique names, as Erwin suggested.
     
    Darko, Mar 7, 2007
    #3
  4. OmegaJunior Guest

    On Wed, 07 Mar 2007 11:00:16 +0100, <> wrote:

    >
    > function submitPartsForm(str) {
    >
    > var count=document.getElementsByName("partId");
    > for(var i=0;i<count.length;i++)
    > {
    >
    > document.mylist.myNum.value= document.getElementsByName("partNum")
    > (i).value;
    >
    > }
    >
    > document.forms["mylist"].submit();
    > }
    > myNum[] is a hidden variable and partNum is the name of a text field
    > that has many instances i mean there are many textfields with the same
    > name so it forms a column in a data table.
    >


    One way would be to join the text values together using a join character
    unlikely to appear in the texts, like so:

    function submitPartsForm() {
    var theNodeList = document.getElementsByName("partId");
    var theNodeValues = document.forms["myList"].elements["theNodeValues"];
    if(theNodeList&&theNodeValues) {
    for (var i=0;i<theNodeList.length;i++) {
    if (theNodeList.value) {
    theNodeValues.value += ("|" + theNodeList.value.toString());
    }
    }
    document.forms["myList"].submit();
    }
    }

    (Above script assumes the form has a hidden input (not disabled), named
    "theNodeValues".)

    Then in your server-side script you can use whatever method your language
    uses to split the string into parts using the "|" as a split character.
    Usually this results in an array.

    --
    Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
     
    OmegaJunior, Mar 11, 2007
    #4
    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. Sharon
    Replies:
    3
    Views:
    639
    Patrick.O.Ige
    Nov 23, 2006
  2. Rick
    Replies:
    3
    Views:
    8,193
    Alexey Smirnov
    Apr 13, 2010
  3. GavMc
    Replies:
    4
    Views:
    339
    Evertjan.
    Sep 22, 2005
  4. Roy Adams

    writing from hidden field to text field

    Roy Adams, Dec 20, 2004, in forum: Javascript
    Replies:
    1
    Views:
    197
  5. Roy Adams
    Replies:
    3
    Views:
    269
    Dr John Stockton
    Dec 21, 2004
Loading...

Share This Page