dynamic value addition in the combo box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arsenal69
    New Member
    • Feb 2007
    • 3

    dynamic value addition in the combo box

    Hi there to all.This is arwinder... i have a bit of a problem.. i cant think of the proper code for displaying the values that we select from an another combo box into a new one .. the moment we select a option it should be displayed in the new combo box. how should i do it.> please help.
    the language used is php.along with a mysql.
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Welcome to The Scripts!

    Please elaborate on your problem a bit more than you gave us now.

    It must be clear that you can only do this (the moment we select a option it should be displayed in the new combo box) using JavaScript.

    Ronald :cool:

    Comment

    • xwero
      New Member
      • Feb 2007
      • 99

      #3
      Originally posted by arsenal69
      Hi there to all.This is arwinder... i have a bit of a problem.. i cant think of the proper code for displaying the values that we select from an another combo box into a new one .. the moment we select a option it should be displayed in the new combo box. how should i do it.> please help.
      the language used is php.along with a mysql.
      if you have a listboxe like this

      [HTML]
      <select name="select1[]" size="4">
      <option value="test 1">test 1</option>
      <option value="test 2">test 2</option>
      <option value="test 3">test 3</option>
      <option value="test 4">test 4</option>
      </select>
      <input type="submit" name="clone" value="clone">
      [/HTML]

      you can do
      [PHP]
      <select name="select2" size="4">
      if($_POST['clone']){
      foreach($_POST['select1'] as $copy){
      echo '<option value="'.$copy. '">'.$copy.' </option>';
      }
      }
      </select>
      [/PHP]

      Comment

      • xwero
        New Member
        • Feb 2007
        • 99

        #4
        Originally posted by xwero
        if you have a listboxe like this

        [HTML]
        <select name="select1[]" size="4">
        <option value="test 1">test 1</option>
        <option value="test 2">test 2</option>
        <option value="test 3">test 3</option>
        <option value="test 4">test 4</option>
        </select>
        <input type="submit" name="clone" value="clone">
        [/HTML]

        you can do
        [PHP]
        <select name="select2" size="4">
        if($_POST['clone']){
        foreach($_POST['select1'] as $copy){
        echo '<option value="'.$copy. '">'.$copy.' </option>';
        }
        }
        </select>
        [/PHP]

        the html of the second combo can go inside of the post if if you want the second combo box not to be visible without options.

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          xwero: your code works fine if you want to submit the form after selecting an entry.

          But the question was: "the moment we select a option it should be displayed in the new combo box. ".

          And that means without submitting the form: i.e. dynamically. Hence the required usage of JavaScript, probably the onchange() function.

          Ronald :cool:

          Comment

          • xwero
            New Member
            • Feb 2007
            • 99

            #6
            Originally posted by ronverdonk
            xwero: your code works fine if you want to submit the form after selecting an entry.

            But the question was: "the moment we select a option it should be displayed in the new combo box. ".

            And that means without submitting the form: i.e. dynamically. Hence the required usage of JavaScript, probably the onchange() function.

            Ronald :cool:
            @ronverdonk:

            I think you said somewhere this is a php forum so this is the php solution ;) I didn't say it i just offered the solution :)

            Comment

            • ronverdonk
              Recognized Expert Specialist
              • Jul 2006
              • 4259

              #7
              I don't doubt your solution, but the post explicitly stated that requirement.

              Maybe I should have posted my reply differently like: "this is not possible in PHP, but when you are prepared to use JS you can do it as a combination of PHP and JS".

              Ronald :cool:

              Comment

              • arsenal69
                New Member
                • Feb 2007
                • 3

                #8
                thanks u guys...
                i'll be more specific next time..
                it was really helpful..

                Comment

                • maygreg
                  New Member
                  • Oct 2007
                  • 1

                  #9
                  I have a similiar issue. I can get the options to move from one combo box to the other that is not a problem. What I'm having problems doing is once I move the values over to this new box how do I create an array to POST the values to another PHP page.

                  Comment

                  Working...