2013-10-19 256 views
0

我必須從選擇標籤數據而不是選擇值作爲選擇值默認從選擇標籤

<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值,並將其存儲在我的D B。如何去做任何想法。

在此先感謝

Ameeth

+5

這麼簡單'值= 「12:00 AM - 15:00 PM」' –

+0

您的選擇框是動態的還是靜態的? – DS9

+0

您使用的選項標籤中的值將在其他/同一頁上的POST/GET從您的form..so watever值中存儲到您的DB中,將這些值作爲選項標籤中的值 – Ashish

回答

2
<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. 使用12:00AM - 15:00PM裏面的value=""參數。

OR

  1. 做這樣的事情在PHP文件收集數據並將其插入到數據庫;

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

我想要的價值和數據我想發佈的數據只有不值我想要12:00Am -15:00PM不會發布155這樣的值,因爲值用於ajax reterival – user2610240