1

i have to select data from select tag rather then selecting value as its selects value for default

<select name="time"  >
        <option selected="selected" >timings</option>
        <option value="155">9:00AM - 12:00PM</option>
        <option value="244">12:00AM - 15:00PM</option>
        </select>

I want to select 12:00AM - 15:00PM values and store it in my DB. How to do it any ideas.

Thanks in advance

Ameeth

Ankur Dhanuka
  • 1,217
  • 2
  • 11
  • 22
user2610240
  • 25
  • 1
  • 9
  • 5
    Simple as `value="12:00AM - 15:00PM"` – M Khalid Junaid Oct 19 '13 at 09:57
  • your select box is dynamic or static? – DS9 Oct 19 '13 at 09:59
  • value which u r using in option tag will POST/GET on other/same page from ur form..so watever values u want to store into ur DB, take those values as value in Option tag –  Oct 19 '13 at 10:00
  • Check : [get the selected index value of – Uours Oct 19 '13 at 10:10
  • possible duplicate of [get the text of the selected option using php](http://stackoverflow.com/questions/11926906/get-the-text-of-the-selected-option-using-php) – M Khalid Junaid Oct 19 '13 at 10:11

2 Answers2

3
<select name="time">
        <option selected="selected" >timings</option>
        <option value="9:00AM - 12:00PM">9:00AM - 12:00PM</option>
        <option value="12:00AM - 15:00PM">12:00AM - 15:00PM</option>
        </select>

<?php
$value = $_POST["time"];  //what method you are using
?>

or

<select name="time"  >
        <option selected="selected" >timings</option>
        <option value="155">9:00AM - 12:00PM</option>
        <option value="244">12:00AM - 15:00PM</option>
</select>

 <?php
  $value = "";
  switch($_POST['time']){
     case '155':
     $value="9:00AM - 12:00PM";
     break;
     case '244':
     $value = "12:00AM - 15:00PM";
     break;
     default:
     $value = "No data found";  
     break;
  } 
?>
raduns
  • 765
  • 7
  • 18
1

You've two options;

  1. Use 12:00AM - 15:00PM inside the value="" parameter.

OR

  1. Do something like this in PHP file for collecting data and inserting it into db;

    if ($_POST['time'] == "155")
    {
        $time = '9:00AM - 12:00PM';
    }
    elseif ($_POST['time'] == "244")
    {
        $time = '12:00AM - 15:00PM';
    }
    // do rest of the data insertion into db
    
Imran Omer
  • 701
  • 1
  • 8
  • 20
  • i want that value and data too i want to post data only not value i want 12:00Am -15:00PM to post not the value like 155 , as value is used for ajax reterival – user2610240 Oct 19 '13 at 10:13