Retrieve value of selected item

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
taha
Forum Newbie
Posts: 17
Joined: Tue Nov 22, 2005 2:40 pm

Retrieve value of selected item

Post by taha »

How do i retrieve the value inside a selection box.
Right now with this line of code, i'm only getting the index, i need the value:

Code: Select all

$partno      = $_POST['secondChoice'];
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Re: Retrieve value of selected item

Post by foobar »

Please elaborate and provide some more code. What does your form look like, what do you mean by index and value?
taha
Forum Newbie
Posts: 17
Joined: Tue Nov 22, 2005 2:40 pm

Post by taha »

Sorry.
Here's more detail:
On my form i have 2 selection boxes and a load button.
The user first needs to select an option from the first selection box, upon doing so, the second selection box is loaded with items.
Once the user selects an item from the second selection box, they then must press the 'Load' button.
Upon pressing the 'Load' button, i need to query the database for a match of what was selected in both selection boxes.
Here is my code:

Code: Select all

<SELECT NAME="firstChoice" ID="firstChoice" ONCHANGE="selectChange(this, genericform.secondChoice, arrItems1, arrItemsGrp1);"> 
<OPTION VALUE="0"   selected <?php if(@strcmp($_POST['firstChoice'], 'Select Unit')  == 0) echo "SELECTED";?>> Select Unit   </OPTION> 
  <OPTION VALUE="1"            <?php if(@strcmp($_POST['firstChoice'], 'SDC1-2')       == 0) echo "SELECTED";?>> SDC1-2        </OPTION>
  <OPTION VALUE="2"            <?php if(@strcmp($_POST['firstChoice'], 'P73 Kit')      == 0) echo "SELECTED";?>> P73 Kit       </OPTION>
  <OPTION VALUE="3"            <?php if(@strcmp($_POST['firstChoice'], 'MDR2-2')       == 0) echo "SELECTED";?>> MDR2-2        </OPTION>
  <OPTION VALUE="4"            <?php if(@strcmp($_POST['firstChoice'], 'CSD1-3')       == 0) echo "SELECTED";?>> CSD1-3        </OPTION>
  <OPTION VALUE="5"            <?php if(@strcmp($_POST['firstChoice'], 'CSD1-4')       == 0) echo "SELECTED";?>> CSD1-4        </OPTION>
  <OPTION VALUE="6"            <?php if(@strcmp($_POST['firstChoice'], 'MLS1-1')       == 0) echo "SELECTED";?>> MLS1-1        </OPTION>
  </SELECT>
  
Unit Part # <SELECT NAME="secondChoice" ID="secondChoice">   
<INPUT TYPE=submit VALUE="Load" NAME="loadData">

  <?php
  if(isset($_POST['loadData']))
  {
     require_once('./mysql_connect.php');
     $description = $_POST['firstChoice'];
     $partno      = $_POST['secondChoice'];
     $query = "SELECT description, partno FROM systemconfig_generic WHERE $description = description AND $partno = partno";
     $result = @mysql_query($query);
     if($result)
     {
        echo 'Description: ' .$description . '<BR>';
        echo 'Part No Found: ' .$partno . '<BR>';   

     }
     else
     {
        echo 'No Part No Found <BR>';
     }
  }
But my problem lies in the following lines of code:

Code: Select all

$description = $_POST['firstChoice'];
     $partno      = $_POST['secondChoice'];
The $description and $partno variables are holding the index of the selected item, rather than the actual value.
I know its very simple syntax that i'm missing, i thought it would work by adding .value at the end, it gives me a syntax.

Does this make sense??
Post Reply