2014-08-27 24 views
0

需要你的幫助變化選擇框自動完成的jQuery的PHP回聲

我想改變選擇框,自動完成的jQuery 我在這裏的工作選擇框

<select name="sShippingPayment" title="simple;<?php echo $lang['Select_shipping_and_payment']; ?>" onchange="countShippingPrice(this)" id="oShippingPayment"> 
<option value=""><?php echo $lang['Select']; ?></option> 
<?php echo $sShippingPaymentSelect; ?> 
</select> 

,並在這裏我jQuery的

<form action='' method='post'> 
<p><label>Shipping & Payment:</label><input type='text' name='sShippingPayment' value='' class='auto'></p> 
</form> 

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script> 
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.min.js"></script>  
<script type="text/javascript"> 
$(function() { 
//autocomplete 
$(".auto").autocomplete({ 
source: <?php echo $sShippingPaymentSelect; ?>, 
minLength: 1 
}); 

}); 
代碼

但它不會工作,請幫助我。

我檢查PHP文件

* Returns shipping and payment select 
    * @return string 
    */ 
    public function throwShippingPaymentsSelect(){ 
    $aShipping = $this->throwPaymentsShipping(2); 
    $aPayments = $this->throwPaymentsShipping(1); 
    if(isset($aShipping) && isset($aPayments)){ 
     $content = null; 
     foreach($aShipping as $iShipping => $aData){ 
     if(isset($aData['aPayments'])){ 
      foreach($aData['aPayments'] as $iPayment => $sPriceModify){ 
      if(isset($aPayments[$iPayment])){ 
       $fShippingPaymentPrice = !empty($sPriceModify) ? generatePrice($aData['fPrice'], $sPriceModify) : $aData['fPrice']; 
       $content .= 
       '<option value="'.$iShipping.';'.$iPayment.';'.$fShippingPaymentPrice.'">'. 
       $aData['sName'].' : Rp. '. 
       displayPrice($fShippingPaymentPrice) 
       .'</option>'; 
      } 
      } // end foreach 
     } 
     } // end foreach 
     return $content; 
    } 
    } // end function throwShippingPaymentsSelect 

我應該不需要更改

 $content .= 
     '<option value="'.$iShipping.';'.$iPayment.';'.$fShippingPaymentPrice.'">'. 
     $aData['sName'].' : Rp. '. 
     displayPrice($fShippingPaymentPrice) 
     .'</option>'; 

被理解爲自動完成源?請幫助如何改變這一點。

真的非常感謝您的回答。

+1

「不起作用」是什麼意思?它現在在做什麼? – dudewad 2014-08-27 21:00:45

回答

1

依我看你需要用你的php回聲輸出引號:

//autocomplete 
$(".auto").autocomplete({ 
source: <?php echo '"' . $sShippingPaymentSelect . '"'; ?>, 
minLength: 1 
}); 

但沒有「它不會工作」的描述,我們不能幫助你更進一步。

+0

這是一個小清潔器來包裝它像'source:「<?php echo $ sShippingPaymentSelect;?>」,' – Sean 2014-08-27 21:03:37

+0

當然,無論漂浮你的船。這是可讀性很差的情況之一。老實說,我會將引號直接添加到變量值本身。 – dudewad 2014-08-27 21:09:31

+0

感謝dudewad和sean,兩個來源:<?php echo'''。$ sShippingPaymentSelect。'「'; ?>,&source:「<?php echo $ sShippingPaymentSelect;?>」,仍然不適合我。這一行<?php echo $ sShippingPaymentSelect; ?>在瀏覽器上打印良好,但自動完成腳本仍然無法抓住它。這裏是我的試用網站http://reseller.site50.net/?order-form.16 – ddk 2014-08-28 04:58:01