8 Replies - 314030 Views - Last Post: 29 March 2012 - 04:23 AM Rate Topic: -----

#1 fsloke  Icon User is offline

  • D.I.C Regular

Reputation: 25
  • View blog
  • Posts: 412
  • Joined: 19-December 07

How to get the select value from the Drop Down list?

Posted 08 April 2008 - 04:22 AM

How to get the select value from the Drop Down list?

Thank
Is This A Good Question/Topic? 0
  • +

#17 spearfish  Icon User is offline

  • Monkey in Training
  • member icon

Reputation: 10
  • View blog
  • Posts: 746
  • Joined: 10-March 08

Re: How to get the select value from the Drop Down list?

Posted 08 April 2008 - 06:29 AM

Take this HTML form example:
<form action="process.php" method='post'>
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
<input type="submit" />
</form>



On process.php; you could pull the value of whatever option was selected. So if "Audi" was selected and submit was hit, $_POST['cars'] would be audi
Was This Post Helpful? 1

#33 c0mrade  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 412
  • Joined: 16-November 07

Re: How to get the select value from the Drop Down list?

Posted 08 April 2008 - 10:20 PM

Also note that the 'super global' ($_POST) is dependent on the 'method' from the form.

'$_POST' for 'method=post'
'$_GET' for 'method=get'
'$_REQUEST' for either/both
Was This Post Helpful? 2

#34 Guest_subhash*


Reputation:

Re: How to get the select value from the Drop Down list?

Posted 03 May 2010 - 11:45 PM

how to dropdown list selected value match the database ?
Was This Post Helpful? 0

#35 Guest_subhash*


Reputation:

Re: How to get the select value from the Drop Down list?

Posted 03 May 2010 - 11:49 PM

my arrow select of dropdown list one value and and select this value match of how to database match in value?
Was This Post Helpful? 0

#36 LiDoNg_9_0  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 159
  • Joined: 03-September 09

Re: How to get the select value from the Drop Down list?

Posted 04 May 2010 - 06:37 PM

View Postsubhash, on 03 May 2010 - 10:45 PM, said:

how to dropdown list selected value match the database ?



ok.. im a little bit confused about your question.
did you mean "How to auto-select from the drop down list that's similar from the database data?"..
Was This Post Helpful? 0
  • +
  • -

#37 LiDoNg_9_0  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 159
  • Joined: 03-September 09

Re: How to get the select value from the Drop Down list?

Posted 04 May 2010 - 06:50 PM

View Postsubhash, on 03 May 2010 - 10:45 PM, said:

how to dropdown list selected value match the database ?


<?php
$mycar = "Toyota"; ///let say the value of this variable is from the database..

///this are the cars available
$cars[0]="Saab";
$cars[1]="Volvo";
$cars[2]="BMW";
$cars[3]="Toyota"; 

echo "
     <form action='process.php' method='post'>
     <select name='cars'>";

     for ($i=0; $i<=4; $i++)
     {
        if($mycar == $cars[$i]){
          echo "<option selected value='$cars[$i]'>$cars[$i]</option>";
        }else {
          echo "<option value='$cars[$i]'>$cars[$i]</option>";
        }
     }

echo" </select>
<input type='submit' />
</form>";


?>





Was This Post Helpful? 0
  • +
  • -

#38 Agix  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 29-March 12

Re: How to get the select value from the Drop Down list?

Posted 29 March 2012 - 04:00 AM

View Postsubhash, on 03 May 2010 - 11:45 PM, said:

how to dropdown list selected value match the database ?


To get values directly out of the database into the options you can use this:
*This is with ID in database, like: 1 = Audio etc.*

Select Car:
    <form method="post" action="process.php">
    <label for="select"><select name="car" value="Select" size="1"> 
<?php 

    $sql = "SELECT * FROM cars";  
    $result = mysql_query($sql) or die (mysql_error());  
    while ($row = mysql_fetch_array($result)) 
    { 
            $id=$row["id"]; 
            $car=$row["car"];  
            $options.="<OPTION VALUE=\"$id\">".$car; 
    } 
    ?> 
            <option>
            <? echo $options ?>
            </option>
        </select>
       <input type="submit" name="Submit" value="Submit">
    </form>


Hope it helps!
Was This Post Helpful? 0
  • +
  • -

#39 Duckington  Icon User is offline

  • D.I.C Addict

Reputation: 170
  • View blog
  • Posts: 608
  • Joined: 12-October 09

Re: How to get the select value from the Drop Down list?

Posted 29 March 2012 - 04:23 AM

4 years later...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1