doubeng9407 2013-09-04 18:38
浏览 28
已采纳

为CakePHP创建自定义确认弹出窗口

I'm dealing with editing reservations and adjusting payments based on this. If a reservation is extended, then I need to charge the customer for the extent of this, likewise, if it's shortened I need to refund.

I tried something like this (without actually POSTing anything, just a confirm box), but even when pressed cancel it submitted the form anyway.

<?php echo $this->Form->create('edit',array('onsubmit'=>'return check_dates()')); ?>
//rest of form here

<script>
function check_dates(){
   //make POST request to check previous reservation duration
   if(data.duration == 'longer'){
       confirm('The guest will be charged $X. Click OK to continue');
   }
   if(data.duration == 'shorter'){
       confirm('The guest will be refunded $X. Click OK to continue');
   }
   if(data.duration == 'no_change'){
       confirm('Click OK to continue')
   }
}
</script>

Is it possible to do something like this? As I mentioned previously, when I pressed cancel the form submitted anyway.

  • 写回答

1条回答 默认 最新

  • dpjo15650 2013-09-04 19:09
    关注

    Checkout this live demo: http://jsbin.com/iZididi/2

    Here in your check_dates(), you have to set return. if you want the form to submit whatever the answer with confirm just you have replace the last line to be

    function check_dates(){
         data = new Object();
      data.duration = 'shorter';
    
      if(data.duration == 'longer'){
           a = confirm('The guest will be charged $X. Click OK to continue');
       }
       if(data.duration == 'shorter'){
           a = confirm('The guest will be refunded $X. Click OK to continue');
       }
       if(data.duration == 'no_change'){
          a = confirm('Click OK to continue')
       }
    
      //return a;
      return true;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化