Ajax Submit Button Issue



In image showing two ajax button showed. While page loading ajax button id created like yt0,yt1,yt2… etc.

then I loaded part of page using ajax then again it created ajax button yt0,yt1, like that…

I want to create another ajax button series like yw0 or something like that…

How to do that???

I suppose you want to identify the buttons, then, why don’t you set id property for AjaxSubmitButton?


     'the button label',

     'the URL for the AJAX request',

     'AJAX options',

     array('id' => 'desiredId') // HTML options for the button.



Yii is a php framework, the CHtml::ajaxbutton is intended to be an helper, not an althernative to jquery ajax.

If you are going to do more complicated works with ajax, be prepared to write your own js code instead of use yii helpers.

Thanks for your reply…

I cant give ID as static bcoz like that more ajax content will get load, then every button id will be the same.

It wont work unless I give dynamic id.

This is a typical problem of the helpers.

The helpers get a dynamic id like yt0, yt1 and the counter is restarted at each render.

So you load ajax content that has the same counter and the same id.

A pure js solution is not to use the yii helpers, which are great but does not cover all cases, and use a js instead.

For example you can give a class to the button and then register the script:

$('body').delegate('.myclass', 'click', function(e){


   //do something


If all the button are suposed to do the same you can just delegate, as delegate works with all instances, even "future" one.


<?php echo CHtml::ajaxButton(‘ajaxbutton’,




				'beforeSend' =&gt; &quot;function(request)




				'success' =&gt; &quot;function(data)


					//alert (data)



				 'error' =&gt; &quot;function(data)


					// handle return data



				'data' =&gt; 'js:&#036;(&quot;#detail-form&quot;).serialize()',



				'href' =&gt; Yii::app()-&gt;createUrl('post',array('postid'=&gt;&#036;post-&gt;post_id))




Try this way. I hope it should work.


chandran nepolean