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 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分