javascript - YII: Assign value to a variable from onclick method -


good afternoon i've been struggling these 2 days , i'm running out of time...

i have modal...

    <div class="modal-header">     <a class="close" data-dismiss="modal">&times;</a>     <?php if ( $modaltoopen == "1") { ?>         <h4>aplicar abono la cuenta #<?php echo $cardinformation->cardnumber ?></h4>     <?php } ?>     <?php if ($modaltoopen == "2") { ?>         <h4>aplicar cargo la cuenta #<?php echo $cardinformation->cardnumber ?></h4>     <?php } ?>  </div>  <div class="modal-body">     <p>saldo actual: <?php echo $lastbalance ?></p>     <?php echo $modaltoopen ; if($modaltoopen == 1){ ?>     <?php $form = $this->beginwidget('bootstrap.widgets.tbactiveform', array('id' => 'inlineform', 'type' => 'inline', 'htmloptions' => array('class' => 'well'))); ?>     <?php echo $form->textfield($auxmodel, 'payment', array('size' => 8, 'maxlength' => 8, 'placeholder' => "$. abono", 'class' => 'span1')); ?>     <?php echo $form->textfield($auxmodel, 'coment', array('size' => 250, 'maxlength' => 250, 'placeholder' => "comentario", 'class' => 'span3')); ?>     <?php     $this->widget(             'bootstrap.widgets.tbbutton', array(             'buttontype' => 'ajaxbutton',             'type' => 'primary',             'label' => 'guardar',             'url' => yii::app()->createurl('businesstargetcollectioncard/applypayment'),             'htmloptions' => array('onclick' => 'showwait();','id' =>'payment-btn'.  uniqid()),             'ajaxoptions' => array(                 'type' => 'post',                 'datatype' => 'json',                 'data' => array(                     'cardnumber' => $cardinformation->cardnumber,                     'lastbalance' => $lastbalance,                     'coment' => 'js:$("#businesstargetcollectioncardmovement_coment").val()',                     'payment' => 'js:$("#businesstargetcollectioncardmovement_payment").val()',                     'businesstargetcollectioncardid' => $cardinformation->id,                     'collectorid' => $cardinformation->collectorid),                 'success' => 'js:function(data){                         alert(data.message);                         if(data.status == "ok"){                             $("#paymentmodal").modal("hide");                             hidewait();                         }                     }'             ),         )     );     $this->endwidget(); ?>     <?php } ?>     <?php if($modaltoopen == 2){ ?>     <?php $form = $this->beginwidget('bootstrap.widgets.tbactiveform', array('id' => 'inlineform', 'type' => 'inline', 'htmloptions' => array('class' => 'well'))); ?>     <?php echo $form->textfield($auxmodel, 'balanceafter', array('size' => 8, 'maxlength' => 8, 'placeholder' => "cantidad aplicar", 'class' => 'span1')); ?>     <?php     $this->widget(             'bootstrap.widgets.tbbutton', array(                 'buttontype' => 'ajaxbutton',                 'type' => 'primary',                 'label' => 'guardar',                 'url' => yii::app()->createurl('businesstargetcollectioncard/applycharge'),                 'htmloptions' => array('onclick' => 'showwait();', 'id' => 'charge-btn' . uniqid()),                 'ajaxoptions' => array(                     'type' => 'post',                     'datatype' => 'json',                     'data' => array(                         'cardnumber' => $cardinformation->cardnumber,                         'charge' => 'js:$("#businesstargetcollectioncardmovement_balanceafter").val()'),                     'success' => 'js:function(data){                             alert(data.message);                             if(data.status == "ok"){                                 $("#mymodal").modal("hide");                                 hidewait();                             }                         }'                 ),             )     );      $this->endwidget();     ?>     <?php } ?>  </div> 

and have these buttons:

<td><?php             $this->widget(                     'bootstrap.widgets.tbbutton', array(                     'label' => 'aplicar cargo',                     'type' => 'success',                     'htmloptions' => array(                         'onclick' => dont know // 'js:$("#modaltoopen").val("1");',                         'data-toggle' => 'modal',                         'data-target' => '#mymodal',                     ),                 )             );             ?></td>          <td></td>         <td><?php             $this->widget(                     'bootstrap.widgets.tbbutton', array(                     'label' => 'aplicar pago',                     'type' => 'primary',                     'htmloptions' => array(                         'onclick' => dont know //'js:$("#modaltoopen").val("2");',                         'data-toggle' => 'modal',                         'data-target' => '#mymodal',                     ),                 )             );             ?></td> 

what want change value of $modaltoopen depending on button clicked... content of modal different if button 1 clicked or button 2...

please appreacciated

you can pass through data-id

<?php             $this->widget(                     'bootstrap.widgets.tbbutton', array(                     'label' => 'aplicar cargo',                     'type' => 'success',                     'htmloptions' => array(                         'onclick' =>'js:function(data){                           var myvalue = $(this).data("id");                           $(".modal-body #myvalue").val(myvalue);                               }',                         'data-toggle' => 'modal',                         'data-target' => '#mymodal',                         'data-id'=>'1',                     ),                 )             );             ?> 

take value in 1 hidden or text in

<div class="modal-body">         <p>some content</p>       <input type="text" name="myvalue" id="myvalue" value=""/> </div> 

i hope help.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -