开发者

hours and days of business ( form select )

Ok.

I want to create a form, that uses the least amount of code possible, for users to display their opening times and days that their store is open.

I know we can use time picker to select from time and to time.

I want to display:

Monday

Tuesday

Wednesday

Thursday

Friday

Saturday

Sunday

With opening times from and to, and a close checkbox Next to each day

But it seems coding this will use heaps of html, is their a cleaner way of coding it. Also not sure how to code the close checkbox to discount an entry for a day, so that its value isnt submitted.

Code below: for Monday

<label>Monday: </label><select name="from"  id="from">
  <option value="06:00">6:00 AM</option> <option value="06:30">6:30 AM</option> <option value="07:00">7:00 AM</option> <option value="07:30">7:30 AM</option> <option value="08:00">8:00 AM</option> <option value="08:30">8:30 AM</option> <option value="09:00"  selected>9:00 AM</option> <option value="09:30">9:30 AM</option> <option value="10:00">10:00 AM</option> <option value="10:30">10:30 AM</option> <option value="11:00">11:00 AM</option> <option value="11:30">11:30 AM</option>开发者_Go百科 <option value="12:00">12:00 PM</option> <option value="12:30">12:30 PM</option> <option value="13:00">1:00 PM</option> <option value="13:30">1:30 PM</option> <option value="14:00">2:00 PM</option> <option value="14:30">2:30 PM</option> <option value="15:00">3:00 PM</option> <option value="15:30">3:30 PM</option> <option value="16:00">4:00 PM</option> <option value="16:30">4:30 PM</option> <option value="17:00">5:00 PM</option> <option value="17:30">5:30 PM</option> <option value="18:00">6:00 PM</option> <option value="18:30">6:30 PM</option> <option value="19:00">7:00 PM</option> <option value="19:30">7:30 PM</option> <option value="20:00">8:00 PM</option> <option value="20:30">8:30 PM</option> <option value="21:00">9:00 PM</option> <option value="21:30">9:30 PM</option> <option value="22:00">10:00 PM</option>
  </select>
  <label>to</label>
  <select name="to"  id="to">
  <option value="06:00">6:00 AM</option> <option value="06:30">6:30 AM</option> <option value="07:00">7:00 AM</option> <option value="07:30">7:30 AM</option> <option value="08:00">8:00 AM</option> <option value="08:30">8:30 AM</option> <option value="09:00">9:00 AM</option> <option value="09:30">9:30 AM</option> <option value="10:00">10:00 AM</option> <option value="10:30">10:30 AM</option> <option value="11:00">11:00 AM</option> <option value="11:30">11:30 AM</option> <option value="12:00">12:00 PM</option> <option value="12:30">12:30 PM</option> <option value="13:00">1:00 PM</option> <option value="13:30">1:30 PM</option> <option value="14:00">2:00 PM</option> <option value="14:30">2:30 PM</option> <option value="15:00">3:00 PM</option> <option value="15:30">3:30 PM</option> <option value="16:00">4:00 PM</option> <option value="16:30">4:30 PM</option> <option value="17:00" selected>5:00 PM</option> <option value="17:30">5:30 PM</option> <option value="18:00">6:00 PM</option> <option value="18:30">6:30 PM</option> <option value="19:00">7:00 PM</option> <option value="19:30">7:30 PM</option> <option value="20:00">8:00 PM</option> <option value="20:30">8:30 PM</option> <option value="21:00">9:00 PM</option> <option value="21:30">9:30 PM</option> <option value="22:00">10:00 PM</option>
  </select>
  <input type="checkbox" name="closed" value="closed">
<font size="-1"><span>Closed</span>

fiddle: http://www.jsfiddle.net/mf2PB/


I can think of several things, although it all depends on the usage. In reality, all of this is in the HTML, so in the end it is a bit of text that most people won't see.

  1. Use JavaScript could populate the options for you, but it would then depend on JavaScript support. In reality, it just makes your initial html smaller, but you add the JavaScipt code and the DOM elements end up being the same.
           http://www.jsfiddle.net/urQc4/

  2. Do this in server-side script.

  3. Split your options into hour/minute:
           http://www.jsfiddle.net/q4KcM/

As far as disabling when the closed checkbox is selected, you would need to do that in your form handling, or in a preprocessing script, which would be JavaScript again.


You could also use a simple text input field where the user can input things like "6:00 AM - 7:00 PM"and some server side code to check if the time range is valid. To make it easier for the user, use a jQuery UI Slider with a range and 48 possible steps.


   function sa_cl() {
    document.getElementById("sa_service_open_time").disabled = true;
    document.getElementById("sa_service_close_time").disabled = true;
  }
  function sa_op() {
    document.getElementById("sa_service_open_time").disabled = false;
    document.getElementById("sa_service_close_time").disabled = false;
  }
  function su_cl() {
    document.getElementById("su_service_open_time").disabled = true;
    document.getElementById("su_service_close_time").disabled = true;
  }
  function su_op() {
    document.getElementById("su_service_open_time").disabled = false;
    document.getElementById("su_service_close_time").disabled = false;
  }
  function mo_cl() {
    document.getElementById("mo_service_open_time").disabled = true;
    document.getElementById("mo_service_close_time").disabled = true;
  }
  function mo_op() {
    document.getElementById("mo_service_open_time").disabled = false;
    document.getElementById("mo_service_close_time").disabled = false;
  }
  function tu_cl() {
    document.getElementById("tu_service_open_time").disabled = true;
    document.getElementById("tu_service_close_time").disabled = true;
  }
  function tu_op() {
    document.getElementById("tu_service_open_time").disabled = false;
    document.getElementById("tu_service_close_time").disabled = false;
  }
  function we_cl() {
    document.getElementById("we_service_open_time").disabled = true;
    document.getElementById("we_service_close_time").disabled = true;
  }
  function we_op() {
    document.getElementById("we_service_open_time").disabled = false;
    document.getElementById("we_service_close_time").disabled = false;
  }
  function th_cl() {
    document.getElementById("th_service_open_time").disabled = true;
    document.getElementById("th_service_close_time").disabled = true;
  }
  function th_op() {
    document.getElementById("th_service_open_time").disabled = false;
    document.getElementById("th_service_close_time").disabled = false;
  }
  function fr_cl() {
    document.getElementById("fr_service_open_time").disabled = true;
    document.getElementById("fr_service_close_time").disabled = true;
  }
  function fr_op() {
    document.getElementById("fr_service_open_time").disabled = false;
    document.getElementById("fr_service_close_time").disabled = false;
  }
    <label for="saturday">Saturday</label> 
    <input type="radio" name="saturday" onchange="sa_cl()">Close
    <input type="radio" name="saturday" onchange="sa_op()">Open<br>
    <label for="sa_service_open_time">Opening Time</label>
    <input type="time" id="sa_service_open_time" name="sa_service_open_time">
    <label for="sa_service_close_time">Closing Time  </label>
    <input type="time" id="sa_service_close_time" name="sa_service_close_time">
    <br><br>

    <label for="sunday">Sunday</label> 
    <input type="radio" name="sunday" onchange="su_cl()">Close
    <input type="radio" name="sunday" onchange="su_op()">Open<br>
    <label for="su_service_open_time">Opening Time</label>
    <input type="time" id="su_service_open_time" name="su_service_open_time">
    <label for="su_service_close_time">Closing Time  </label>
    <input type="time" id="su_service_close_time" name="su_service_close_time">

    <br><br><label for="monday">Monday</label> 
    <input type="radio" name="monday" onchange="mo_cl()">Close
    <input type="radio" name="monday" onchange="mo_op()">Open<br>
    <label for="mo_service_open_time">Opening Time</label>
    <input type="time" id="mo_service_open_time" name="mo_service_open_time">
    <label for="mo_service_close_time">Closing Time  </label>
    <input type="time" id="mo_service_close_time" name="mo_service_close_time">

    <br><br><label for="tuesday">Tuesday</label><br>
    <input type="radio" name="tuesday" onchange="tu_cl()">Close
    <input type="radio" name="tuesday" onchange="tu_op()">Open<br>
    <label for="tu_service_open_time">Opening Time</label>
    <input type="time" id="tu_service_open_time" name="tu_service_open_time">
    <label for="tu_service_close_time">Closing Time  </label>
    <input type="time" id="tu_service_close_time" name="tu_service_close_time">

    <br><br><label for="wednesday">Wednesday</label><br>
    <input type="radio" name="wednesday" onchange="we_cl()">Close
    <input type="radio" name="wednesday" onchange="we_op()">Open<br>
    <label for="we_service_open_time">Opening Time</label>
    <input type="time" id="we_service_open_time" name="we_service_open_time">
    <label for="we_service_close_time">Closing Time  </label>
    <input type="time" id="we_service_close_time" name="we_service_close_time">

    <br><br><label for="thursday">Thursday</label><br>
    <input type="radio" name="thursday" onchange="th_cl()">Close
    <input type="radio" name="thursday" onchange="th_op()">Open<br>
    <label for="th_service_open_time">Opening Time</label>
    <input type="time" id="th_service_open_time" name="th_service_open_time">
    <label for="th_service_close_time">Closing Time  </label>
    <input type="time" id="th_service_close_time" name="th_service_close_time">

    <br><br><label for="friday">Friday</label><br>
    <input type="radio" name="friday" onchange="fr_cl()">Close
    <input type="radio" name="friday" onchange="fr_op()">Open<br>
    <label for="fr_service_open_time">Opening Time</label>
    <input type="time" id="fr_service_open_time" name="fr_service_open_time">
    <label for="fr_service_close_time">Closing Time  </label>
    <input type="time" id="fr_service_close_time" name="fr_service_close_time">
    <br><br>

   

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜