I am working on delivery page which has two radio buttons viz.'Regular day time delivery' and 'Require Midnight Delivery'. I want to display another radio button(viz Same day Delivery) if and only if time is 2 PM and 'Regular day time delivery' is checked Otherwise that button will not be visible or will be disabled.
I can disable button using javascript but don't know how to disable it according to time?
Can anyone Help me?
Update1: I want 'Same day Delivery' button to be visible/enabled after 2PM till 7AM next day.
Update2: I am using PHP-Mysql as Backend/server side Technology
You can do it with setIntertval()
function (checking time every minute):
var interv = setInterval(function(){
// from 14 PM till 7 AM
var hours = (new Date()).getHours();
if(hours >= 14 || hours < 7)
$(".sameDay").hide();
else
$(".sameDay").show();
}, 60000);
<!DOCTYPE html>
<html>
<body onload="myFunction();">
<INPUT TYPE="Radio" Name="payment" onclick="myFunction();" Value="CC">Regular day time delivery
<INPUT TYPE="Radio" Name="payment" onclick="func2();" Value="DC">Require Midnight Delivery
<INPUT TYPE="Radio" Name="payment1" id="1" Value="PP" >Same day Delivery
<input type="text" id="h1">
<input type="text" id="h2">
<script>
function myFunction() {
var d = new Date();
var p=Math.floor((d.getTime()/ (1000*60*60)) % 24)
var q=Math.floor((d.getTime()/ (1000*60)) % 60 )
document.getElementById("h1").value=p;
document.getElementById("h2").value=q;
if((p>=1 && q>=30) && ( p<=8 && q<=30) )
{
document.getElementById("1").disabled=false;
}
else
{
document.getElementById("1").disabled=true;
}
}
function func2()
{
document.getElementById("1").checked = false;
document.getElementById("1").disabled=true;
}
</script>
</body>
</html>
Here i used UTC
time so irrespective of client/country you will get standard time.
Also added textbox to check hours.
You can check code here (copy above code) As fiddle is not working http://www.w3schools.com/html/tryit.asp?filename=tryhtml_default
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.