2012-12-06 85 views
1

使用codeigniter生成表單。形式有form_dropdown()jQuery make option selected - CodeIgniter

<div class="control-group"> 
     <?php 
     foreach ($clients as $client => $clientValue) { 
      $option[$clientValue['clientName']] = $clientValue['clientName']; 
     } 
     echo form_label('Client Name:', 'client'); 
     echo form_dropdown('client', $option); 
     ?> 
</div><!-- /control-group --> 

輸出

<select name="client"> 
<option value="Mike">Mike </option> 
<option value="Sissel Bygton">Sissel Bygton</option> 
<option value="Calli Crass">Calli Crass</option> 
</select> 

使用Javascript/jQuery的

var clientName = json.selected_gallery[0].clientName; //clientName retrieved from DB 

//alert box to confirm clientName for this example lets say it's Mike 
alert(clientName)//output Mike 

//Client Select name 
$('select.client').val(clientName); 

從我通過其他Q &起皺的,我會認爲我的jQuery會做的伎倆。我是否留下了一些東西?

回答

3
<select name="client"> 

選擇應該是

$('select[name="client"]').val(clientName); 

如果你想使用一個類,那麼

<select class="client"> 

對上述選擇它來訪問是

$('select.client').val(clientName); 
+0

衛生署!感謝那。 – Bungdaddy

+0

@Bungdaddy ..不客氣:) –

相關問題