Assigning values back to drop down box

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

    Assigning values back to drop down box

    Group,

    I have several drop down boxes that I'd like to repopulate with the value
    the user selected -- after the form posts by calling itself -- these fields
    are blanked out. I am having difficulty getting the drop downs to repopulate
    with the values the user's selected. If any of you have implemented this
    before, how have you done this and what is the syntax?

    Thanks,


  • Matthias Esken

    #2
    Re: Assigning values back to drop down box

    "TG" <tgillette1@cox .net> schrieb:
    [color=blue]
    > I have several drop down boxes that I'd like to repopulate with the value
    > the user selected -- after the form posts by calling itself -- these fields
    > are blanked out. I am having difficulty getting the drop downs to repopulate
    > with the values the user's selected. If any of you have implemented this
    > before, how have you done this and what is the syntax?[/color]

    This is pure HTML.

    Option 2 is set:

    <option value="1"></option>
    <option value="2" selected='selec ted'></option>
    <option value="3"></option>

    Regards,
    Matthias

    Comment

    • laidbak

      #3
      Re: Assigning values back to drop down box

      >...repopulat e with the value the user selected -- after the form posts by calling itself -- these fields[color=blue]
      >...with the values the user's selected. If any of you have implemented this[/color]

      Here is some sample code that should get you going:

      <?php

      /* this is the form handling code */
      $myselect = '';
      if ( isset( $_POST['myselect'] ) ) { $myselect = $_POST['myselect'] ; }
      if ( isset( $_GET['myselect'] ) ) { $myselect = $_GET['myselect'] ; }

      ?>
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

      <html>
      <head>
      <title>Form Select Handler</title>
      </head>

      <body>
      <form action="<?php $_SERVER['PHP_SELF']; ?>" name="myform" id="myform" method="GET">
      <select name="myselect" id="myselect">
      <option value="1" <?php print ($myselect==1) ? 'SELECTED' : ''; ?>>option1</option>
      <option value="2" <?php print ($myselect==2) ? 'SELECTED' : ''; ?>>option2</option>
      </select>
      <input type="submit">
      </form>
      </body>
      </html>


      --
      ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~
      Wil Moore III, MCP Site : www.quicksitedesign.com?em
      Application Developer Site : www.digitallysmooth.com?em
      ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~

      Comment

      • Tim Van Wassenhove

        #4
        Re: Assigning values back to drop down box

        On 2004-01-14, laidbak <laidbak69@hotm ail.com> wrote:[color=blue]
        > This is a multi-part message in MIME format.
        >
        > ------=_NextPart_000_ 0276_01C3DA2C.5 9E54640
        > Content-Type: text/plain;
        > charset="iso-8859-1"
        > Content-Transfer-Encoding: quoted-printable[/color]

        Only posts in plaintext please.

        Comment

        • Matthias Esken

          #5
          Re: Assigning values back to drop down box

          "laidbak" <laidbak69@hotm ail.com> wrote:
          [color=blue]
          > <div><font face=Arial size=2></font>&nbsp;</div>
          > <div><font face=Courier color=#800000 size=2>&lt;?php </font></div>
          > <div><font face=Courier color=#800000></font>&nbsp;</div>
          >
          > <div><font face=Courier color=#800000 size=2>
          > &nbsp;&nbsp;&nb sp; /* this is the form handling code */<br>
          > &nbsp;&nbsp;&nb sp; $myselect = '';<br>
          > &nbsp;&nbsp;&nb sp; if ( isset( $_POST['myselect'] ) ) { $myselect = $_POST['myselect'] ; }<br>
          > &nbsp;&nbsp;&nb sp; if ( isset( $_GET['myselect'] ) ) { $myselect = $_GET['myselect'] ; }
          > </font></div>
          > <div><font face=Courier color=#800000></font>&nbsp;</div>
          > <div><font face=Courier color=#800000 size=2>?&gt;<br >
          > &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;</font></div>
          > <div><font face=Courier color=#800000></font>&nbsp;</div>
          > <div><font face=Courier color=#800000 size=2>&lt;html &gt;<br>
          > &lt;head&gt;<br >
          > &nbsp;&lt;title &gt;Form Select Handler&lt;/title&gt;<br>
          > &lt;/head&gt;
          > </font></div>
          >
          > <div><font face=Courier color=#800000></font>&nbsp;</div>
          > <div><font face=Courier color=#800000 size=2>&lt;body &gt;<br>
          > &lt;form action="&lt;?ph p $_SERVER['PHP_SELF']; ?&gt;" name="myform" id="myform" method="GET"&gt ;<br>
          > &lt;select name="myselect" id="myselect"&g t;<br>
          > &nbsp;&lt;optio n value="1" &lt;?php print ($myselect==1) ? 'SELECTED' : ''; ?&gt;&gt;option 1&lt;/option&gt;<br>
          > &nbsp;&lt;optio n value="2" &lt;?php print ($myselect==2) ? 'SELECTED' : ''; ?&gt;&gt;option 2&lt;/option&gt;<br>
          > &lt;/select&gt;<br>
          > &lt;input type="submit"&g t;<br>
          > &lt;/form&gt;<br>
          > &lt;/body&gt;<br>
          > &lt;/html&gt;</font></div>
          >
          > <div><font face=Arial size=2></font>&nbsp;</div>[/color]

          This looks very complicated.

          SCNR,
          Matthias

          Comment

          • Rahul Anand

            #6
            Re: Assigning values back to drop down box

            "TG" <tgillette1@cox .net> wrote in message news:<Pu5Nb.323 5$Mb7.2047@lake read04>...[color=blue]
            > Group,
            >
            > I have several drop down boxes that I'd like to repopulate with the value
            > the user selected -- after the form posts by calling itself -- these fields
            > are blanked out. I am having difficulty getting the drop downs to repopulate
            > with the values the user's selected. If any of you have implemented this
            > before, how have you done this and what is the syntax?
            >
            > Thanks,[/color]

            Use a select box like following:

            [HTML]
            <select name="mySelect" >
            <option value="1" <?=$mySelectOpt ion['1']?>>option1</option>
            <option value="2" <?=$mySelectOpt ion['2']?>>option2</option>
            <option value="3" <?=$mySelectOpt ion['3']?>>option3</option>
            <option value="4" <?=$mySelectOpt ion['4']?>>option4</option>
            <option value="5" <?=$mySelectOpt ion['5']?>>option5</option>
            <option value="6" <?=$mySelectOpt ion['6']?>>option6</option>
            </select>
            [/HTML]

            And code your PHP like following:

            [PHP]
            $mySelectOption['1'] =
            $mySelectOption['2'] =
            $mySelectOption['3'] =
            $mySelectOption['4'] =
            $mySelectOption['5'] =
            $mySelectOption['6'] = '';
            if(!empty($_REQ UEST['mySelect']))
            $mySelectOption[$_REQUEST['mySelect']] = 'selected';
            else
            $mySelectOption[1] = 'selected'; // Default selected, for first time

            [/PHP]

            This is just a possible way to achieve this.
            Another method will be output your Select box in a loop and check for
            selected condition, and ouput the *selected* text when necessary.

            --
            Cheers,
            Rahul

            Comment

            • Guest's Avatar

              #7
              Re: Assigning values back to drop down box

              "Matthias Esken" <muelleimer2003 nospam@usenetve rwaltung.org> wrote in message
              news:bu34k0.3dc .1@usenet.esken .de...[color=blue]
              > "laidbak" <laidbak69@hotm ail.com> wrote:
              >[color=green]
              > > <div><font face=Arial size=2></font>&nbsp;</div>
              > > <div><font face=Courier color=#800000 size=2>&lt;?php </font></div>
              > > <div><font face=Courier color=#800000></font>&nbsp;</div>[/color][/color]
              <snip>[color=blue]
              >
              > This looks very complicated.[/color]

              That's because it is an HTML reply post, which your newsreader apparently
              does not understand. That is the reason HTML posts on usenet are discouraged.
              (http://www.usenet.org.uk/ukpost.html#s2)


              Comment

              • Chung Leong

                #8
                Re: Assigning values back to drop down box

                Personally I like to do this:

                <? $selected = array($menu => "selected") ; ?>
                <select name="menu">
                <option value="1" <?=$selected[1]?>>Item 1</option>
                <option value="2" <?=$selected[2]?>>Item 2</option>
                <option value="3" <?=$selected[3]?>>Item 3</option>
                </select>

                Uzytkownik "TG" <tgillette1@cox .net> napisal w wiadomosci
                news:Pu5Nb.3235 $Mb7.2047@laker ead04...[color=blue]
                > Group,
                >
                > I have several drop down boxes that I'd like to repopulate with the value
                > the user selected -- after the form posts by calling itself -- these[/color]
                fields[color=blue]
                > are blanked out. I am having difficulty getting the drop downs to[/color]
                repopulate[color=blue]
                > with the values the user's selected. If any of you have implemented this
                > before, how have you done this and what is the syntax?
                >
                > Thanks,
                >
                >[/color]


                Comment

                Working...