Hi,

i am trying to retrieve a value from a combo box....i am using this code

<select name="cards">
<?php
echo("
<option value=\"$cardtype\">Visa/Delta/Electron</option>\n
<option value=\"$cardtype\">Mastercard</option>\n
<option value=\"$cardtype\">EuroCard</option>\n
<option value=\"$cardtype\">American Express</option>\n
<option value=\"$cardtype\">Switch/Solo</option>\n");
?>
</select><hr/><br/>

this data is posting to another page using...

$cardtype    = $HTTP_POST_VARS['CardType'];

This returns an empty value even though i am selecting a value in the combo.....can anbody help..........🙂

    $cardtype_=_$HTTP_POST_VARS['cards'];

    will get you the value of the selected option. To recognise the cards you should of cource enter different values for each card.

      where are you defining the value of $cardtype, and you dont seem to be changing it between using it anyway, so they'll all have the value.

      And yes, since the name of your select is "cards", you should access it using the above, or more commonly now, $_POST['cards']

        Xeq,

        it gives a parse error when you use the code that you suggested. Have you got anymore ideas...?

          jpmoriarty,

          i cant quite understand what you are saying. The $cardtype is being assigned to the value of the combo box isnt it..?

            <select name="cards">
            <option selected>Pick a Card Any Card</option>\n
            <option>Visa/Delta/Electron</option>\n
            <option>Mastercard</option>\n
            <option>EuroCard</option>\n
            <option>American Express</option>\n
            <option>Switch/Solo</option>\n");
            </select>

            Do above and then you can access the value by referencing the $cards variable. Nothing fancy needed. This should work Although I didn't test it.

            Plus I don't see where you even need php to do this. Unless the $cards values are from a mysql table or from a preset array in php.

              hiccup,

              i am using the code that you suggested along with...

              $cardtype = $HTTP_POST_VARS['cardtype'];

              doesnt get any value

                get a book and read how select boxes work in HTML - it's not PHP at all.

                The variable name will be defined by the "name" given to the select box - that's what you've called "cards". It will take the value depending on which one you select in the list - so you should have things like:

                <option value="visa">Visa</option>
                <option value="mastercard">Mastercard</option>
                etc.

                of course the value field does not have to be the same as the name that appears in the box, you could give them numerica values, but then when you refer to $cards (or preferably $_POST['cards'] if your globals are off) then you will get retruned whatever you defined the value as. ( ie mastercard or visa in the eg above).

                But like I keep saying, it's a good idea to have a vague clue of how the HTML works before you try and program it in php - and as hiccup says, you dont need php at all to program this.

                  Write a Reply...