2014-02-26 36 views
0

所以我試圖創建一個循環遍歷$個國家的下拉菜單,然後將所選國家寫入數據庫中用戶表下的$ country。我得到了下拉菜單,但是它向數據庫返回一個空值(至少是驗證)。<select>標記向數據庫返回一個空值

這裏是呼籲下拉

 <div class="form-group col-lg-6 col-sm-12"> 
     <label for="country">Country</label> 
     <div id="countrydd"> 
      @if(isset($currentCountry->name)) 
      <select name="country" id="country_display" class="current-value-da-select closed"> 
       {{(isset($user->country->name))?$user->country->name:$currentCountry->name}} 
       @foreach($countries as $country) 
        <option value="{{$country->name}}">{{$country->name}}</option> 
       @endforeach 
      </select> 

      @else 
      <select name="country" id="country_display" class="current-value-da-select closed"> 
       {{(isset($user->country->name))?$user->country->name:'Select your Country'}} 
       @foreach($countries as $country) 
        <option value="{{$country->name}}">{{$country->name}}</option> 
       @endforeach 
      </select> 

      @endif 

這是JavaScript的下拉

//Country Drop Down 
$('#countrydd').click(function(e) { 
    var selectWrapperCountry = $('#countrydd'); 
    var currentValueCountry = $(this).find('a').html(); 
    selectWrapperCountry.find('.current-value-da-select').html(currentValueCountry); 
    selectWrapperCountry.find('#country').val(currentValueCountry); 
    updateCarretClassCountry(); 
}); 
$('#countrydd a.current-value-da-select').click(function() { 
    updateCarretClassCountry(); 
}); 
function updateCarretClassCountry(){ 
    if($('#countrydd a.current-value-da-select').hasClass('closed')) { 
    $('#countrydd a.current-value-da-select').attr('class', 'current-value-da-select opened'); 
    } 
    else 
    { 
    $('#countrydd a.current-value-da-select').attr('class', 'current-value-da-select closed'); 
    } 
}; 

任何幫助來獲得更新的權利將是真棒值。

回答

3

看來你正在使用select標籤錯誤。選擇需要有一個名稱(這是你會得到一個職位變量),並且每個選項都需要有一個值。因此,這將是這樣的:在提交表單

<select name="country"> 
    <option value="1">First one</option> 
    <option value="2">Second one</option> 
</select> 

後,你將有

echo $_POST["country"]; //This will output 1 if First one is selected and 2 if Second one is 

另外,爲什麼你有<a>裏面<option>

閱讀更多:http://www.w3.org/wiki/HTML/Elements/select

+1

另外''

+0

' – Archer

+1

@DanFromGermany done –

相關問題