dtu72460 2015-12-14 05:46
浏览 34

获取按钮的值并在单击时保存在db中

I want to update a field in db as 1 or 0 when i click on yes or no button..

<td>  <input type="button" onClick="save();" value="Yes">
     <input type="button" onClick="save();" value="No">
     </td>

This code displays the button in view page as yes and no. Now what should i do to save in db while clicking on yes button?

     <div class="bit-4 pad-small"  style="float:none;">
        <br>
        <br>
     <?php echo $this->Form->input('approve', array(
                              'type'=>'checkbox', 
                               'style' => 'float:left;',)
                                 ) ); ?>
           <span>required</span>
          </div>
  • 写回答

3条回答 默认 最新

  • doomli3721 2015-12-14 05:58
    关注

    in your cakephp file you can get the value and update it to database. Hope you can get any way to update it now. Even you can do that in save() method.

    /please change input to any unique selecter give any id or class to button/

        $("input").click(function(){
    
            var val = $(this).val();
    
                $.ajax({url: "path_to_your_cake_php_file.php", 
    
                        type: 'post', // performing a POST request
                        data : {
                          inputValue : val // will be accessible in $_POST['inputValue']
                        },
                        dataType: 'json',
                    success: function(result){
                        alert('value has been updated');
                }});
    
        })
    
    评论

报告相同问题?

悬赏问题

  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数