从select标签中选择数据

时间:2013-10-19 09:51:58

标签: html

我必须从select标签中选择数据,而不是选择value作为默认选择值

<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>

我想选择12:00 AM - 15:00 PM值并将其存储在我的数据库中。怎么做任何想法。

提前致谢

Ameeth

2 个答案:

答案 0 :(得分: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
?>

<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;
  } 
?>

答案 1 :(得分:1)

你有两个选择;

  1. 12:00AM - 15:00PM参数中使用value=""
  2. OR

    1. 在PHP文件中执行类似的操作,以收集数据并将其插入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