rockstardev
rockstardev

Reputation: 13527

YII: How to dynamically pass data to YII Button?

I have a button:

 $this->widget('bootstrap.widgets.TbButton', array(
    'label'=>'Go!',
    'buttonType'=>'ajaxButton', 
    'type'=>'primary', 
    'size'=>'small', 
    'url'=>$this->createUrl('site/go'),
    'ajaxOptions'=>array(
      'type' => 'POST',
      'beforeSend' => '
        function( request ) {
        }'
      ,
      'success' => '
        function( data ) {

        }'
      ,
      'error' => '
        }'
      ,
      'data' => array( 
        'ID' => $ID,
      )
    ),
  ));

As you can see, it's easy to pass static data via the 'data' portion, as I've done with the ID. But, how do I pass through the value of an input box as part of the data variables? For example, if I have:

<input type="text" value="309" id="myInput" />

I want the value of myInput to be one of the variables, just like ID is one of the variables. How do I submit that with ID when the button is pressed?

Upvotes: 0

Views: 769

Answers (1)

Ninad
Ninad

Reputation: 1871

Try something like this for your data part of ajax

'data' => array( 
        "urVariableName" = "js: $('#myInput').val();"
      ),

And in your controller u can get the value using POST or GET

Upvotes: 3

Related Questions