2015-03-03 29 views
-1

我是yii的新手。我有一個組合和一個文本框的表單。現在我想通過改變組合值來改變文本字段的值。 現在我通過更改組合值和url響應得到一個ajax url,也就是10,這是我的正確的文本字段值。我的問題是,我如何使用該值並將其分配給該文本字段。 我textfiels是:如何使用我從雅虎網站收到的價值yii

<input id="Subscription_amount" type="text" value="0" name="Subscription[amount]" > 

我的控制器代碼:

public function actiongetSubAmount() 
{ 
    $data=Subscription::model()->findByPk($_POST['sub_id']); 
    echo $data->amount; 
    exit(); 
} 

響應URL我得到的是從indexController的。

+0

您可以提供控制器代碼嗎? – hamed 2015-03-03 07:38:44

+0

看到我編輯的問題... – 2015-03-03 07:44:22

回答

0

此問題與php或yii無關。你需要通過javascript或jquery來完成這些工作。在阿賈克斯請求的success事件中,您可以這樣做:

.... 
success: function(data){ 
    //data will bee everything you echo in your controller's action 
    //in your case, data will be equal to $data->amount 
    //if you need to pass an object or a list of object to client, you can use json_encode in your controller and $.parseJson in the view. But in your case don't need to use json, because you have only one data field. 
    $("#Subscription_amount").val(data) 
}, 
+0

但我們使用dropDownList像 $ form-> dropDownList($ model,'id',GxHtml :: listDataEx(Model_name :: model() - > findAll(array('condition'= >'id ='。$ id)),'ai_sync_id','name'),array('prompt'=>' - SELECT--'))並且它可以工作.... 因此如何處理的文本框? – 2015-03-03 08:07:24

+0

我認爲這與這個問題沒有關係,但是你可以用它來生成文本字段:$ form-> textField($ model,'fieldName',array('class'=>'className') – hamed 2015-03-03 08:10:36

+0

oh ...您的答案現在有用。謝謝 – 2015-03-03 10:23:50

相關問題