admin管理员组文章数量:1292223
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> <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: /
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> <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/mf2PB/
Share edited Jan 14, 2011 at 23:02 Felix Kling 817k181 gold badges1.1k silver badges1.2k bronze badges asked Jan 14, 2011 at 22:58 422422 5,77024 gold badges86 silver badges140 bronze badges 4- 1 What server side language are you using? Why not generating the HTML on the server side? – Felix Kling Commented Jan 14, 2011 at 23:03
- If you don't mind using a JS UI library, there are tons of different date/time pickers out there. What about something like RightJS? Check out the calendar-with-time demo. – Matt Ball Commented Jan 14, 2011 at 23:07
- We could use php, but I am no php expert. – 422 Commented Jan 14, 2011 at 23:07
- we currently do use a time picker for other elements on the website. But again the code is protracted, I wondered if we could generate the times dynamically, and apend a id to each element. – 422 Commented Jan 14, 2011 at 23:08
3 Answers
Reset to default 6I 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.
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/urQc4/Do this in server-side script.
Split your options into hour/minute:
http://www.jsfiddle/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>
本文标签: javascripthours and days of business ( form select )Stack Overflow
版权声明:本文标题:javascript - hours and days of business ( form select ) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741550010a2384823.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论