Php/Javascript problems with multiple select

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ramses van Pinxteren

    Php/Javascript problems with multiple select

    hello,

    I have a PHP/Javascript problem. If I want to make a multiple select
    like this one:

    $html .= "<td><selec t name='userid' onChange='chang euserinfo()' multiple
    size='10'>";
    $html .= "<option value=''>Select eer user</option>";
    $html .= "<option value='1'>user 1</option>";
    $html .= "<option value='2'>user 2</option>";
    $html .= "<option value='3'>user 3</option>";
    $html .= "<option value='4'>user 4</option>";
    $html .= "<option value='5'>user 5</option>";
    $html .= "<option value='6'>user 6</option>";
    $html .= "</select>";
    $html .= "</td>";

    I can read this one out with javascript but accourding tot the PHP
    manual I have to declare the select as follows to read it out in php:
    $html .= "<td><selec t name='userid[]' multiple size='10'>";
    and this is something that javascript does not want to swallow :'(

    How can i make it so that both javascript and php can access the fields
    and do their usefull stuff with it.

    HELP MEEEEEEE :)

    Greetz,
    Ramses

  • ozias

    #2
    Re: Php/Javascript problems with multiple select


    "Ramses van Pinxteren" <ramsesvp@NOSPA N.quicknet.nl> wrote in message
    news:efb27$401f f994$52d9b2ca$2 9655@news.multi kabel.nl...[color=blue]
    > hello,
    >
    > I have a PHP/Javascript problem. If I want to make a multiple select
    > like this one:
    >
    > $html .= "<td><selec t name='userid' onChange='chang euserinfo()' multiple
    > size='10'>";
    > $html .= "<option value=''>Select eer user</option>";
    > $html .= "<option value='1'>user 1</option>";
    > $html .= "<option value='2'>user 2</option>";
    > $html .= "<option value='3'>user 3</option>";
    > $html .= "<option value='4'>user 4</option>";
    > $html .= "<option value='5'>user 5</option>";
    > $html .= "<option value='6'>user 6</option>";
    > $html .= "</select>";
    > $html .= "</td>";
    >
    > I can read this one out with javascript but accourding tot the PHP
    > manual I have to declare the select as follows to read it out in php:
    > $html .= "<td><selec t name='userid[]' multiple size='10'>";
    > and this is something that javascript does not want to swallow :'(
    >
    > How can i make it so that both javascript and php can access the fields
    > and do their usefull stuff with it.
    >[/color]

    <select id="userid[]" name="userid[]" onchange="chang euserinfo();">

    and in the javascript use

    FormObject=docu ment.forms['name of form'];
    SelectObject=Fo rmObject.elemen ts['userid[]'];

    you can then loop through the array SelectObject.op tions[], checking the
    'selected' property to see which items have been selected

    SelectionCount= 0;
    for(n=0;n<Selec tObject.options .length;n++)
    {
    if(SelectObject .options[n].selected)
    {
    // option selected
    SelectionCount+ +;
    }
    else
    {
    // option not selected
    }
    }

    The SelectObject.se lectedindex property only shows the first selected
    element.
    [color=blue]
    > HELP MEEEEEEE :)
    >
    > Greetz,
    > Ramses
    >[/color]


    Comment

    • Daniel Tryba

      #3
      Re: Php/Javascript problems with multiple select

      Ramses van Pinxteren <ramsesvp@nospa n.quicknet.nl> wrote:[color=blue]
      > I can read this one out with javascript but accourding tot the PHP
      > manual I have to declare the select as follows to read it out in php:
      > $html .= "<td><selec t name='userid[]' multiple size='10'>";
      > and this is something that javascript does not want to swallow :'([/color]

      You are incorrect. Javascript has no problem with elements named like
      'userid[]', us the element name in the elements hash.

      --

      Daniel Tryba

      Comment

      • R. Rajesh Jeba Anbiah

        #4
        Re: Php/Javascript problems with multiple select

        Ramses van Pinxteren <ramsesvp@NOSPA N.quicknet.nl> wrote in message news:<efb27$401 ff994$52d9b2ca$ 29655@news.mult ikabel.nl>...[color=blue]
        > hello,
        >
        > I have a PHP/Javascript problem. If I want to make a multiple select
        > like this one:
        >
        > $html .= "<td><selec t name='userid' onChange='chang euserinfo()' multiple
        > size='10'>";
        > $html .= "<option value=''>Select eer user</option>";
        > $html .= "<option value='1'>user 1</option>";
        > $html .= "<option value='2'>user 2</option>";
        > $html .= "<option value='3'>user 3</option>";
        > $html .= "<option value='4'>user 4</option>";
        > $html .= "<option value='5'>user 5</option>";
        > $html .= "<option value='6'>user 6</option>";
        > $html .= "</select>";
        > $html .= "</td>";
        >
        > I can read this one out with javascript but accourding tot the PHP
        > manual I have to declare the select as follows to read it out in php:
        > $html .= "<td><selec t name='userid[]' multiple size='10'>";
        > and this is something that javascript does not want to swallow :'([/color]

        Read further. It has an answer.
        <http://in2.php.net/manual/en/faq.html.php#fa q.html.select-multiple>

        --
        "Success = 10% sweat + 90% tears"
        Email: rrjanbiah-at-Y!com

        Comment

        Working...