duanlanqian9974 2019-01-03 03:10
浏览 50
已采纳

(课程预订功能)提示用户在单击“在HTML表单上提交”之前选择了周末日期

Intro to the Problem

I am currently developing a Booking Function, Members are able to purchase class packages of two different types, the first being a "Weekday Only" package whilst the other package allows for "All-Days".

I do not want to disable the selection of Weekends and Public Holidays for "Weekday Only" Package holders as they would still need to be able to book these dates albeit with additional costs.

Was wondering if there is any way to inform a "Weekday Only" Package holder that they have selected a Weekend/Public Holiday before they click submit on the HTML form.

The current method

On the Member's Home page they would be able to click the "Book a Class" button as long as their current account has an active package, Saving package information in the mysql as states of '0 = No Package' , '1 = Weekday Only Package' and '2 = Any-Day Package'.

Upon clicking the "Book a Class" button they are redirected to a form that allows the user to select a Date and a Class Slot. Upon submitting the form the day is checked based on the submitted date, If the Member package is state = '1' and the date selected falls on Saturday/Sunday it would prompt the member about the additional costs, before allowing the member to confirm the booking.

The current method is only able to check the date after the submit button has been hit, and the form submitted,

Thank you for your time and input.

  • 写回答

1条回答 默认 最新

  • drzk21632 2019-01-03 04:20
    关注

    In Javascript, you can add an event listener that will fire a handler function that validates the date to determine if it's on a weekend or not every time the input changes.

    In the aforementioned function, you can check if it's the weekend using the getDay() method to validate, something like the code/pseudocode below could be a good start:

    let yourDateField = document.getElementByID("you-date-field");
    
    yourDateField.addEventListener('input', function (evt) {
    
        let selectedDate = new Date(yourDateField.value);
    
        let day = selectedDate.getDay();
    
        if(day === 6){
    
          alert("The date you chose is on a Saturday");
    
        }
        else if(day === 0){
    
          alert("The date you chose is on a Sunday");
    
        }else{
    
          //Proceed with class signup.
    
        }
    
    });
    

    The answer assumes that you don't need to check the database before making the validation.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)