2014-08-27 49 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