/    Sign up×
Community /Pin to ProfileBookmark

hi,
instead of hardcoding in Option array as 08:00—12:10 can i use PHP function in this array to add

<script>
var times = new Array ();
times[0] = new Option(“08:00”, “08:00”);//some PHP function as i dont want to hard code time from 08:00–e23:55 is it possible to use some function to get time from 08:00–23:55
times[1] = new Option(“09:00”, “09:00”);
times[2] = new Option(“12:10”, “12:10”);
function insertTime() {
time = new Date();
hour = time.getHours();
minute = time.getMinutes();
if (minute < 15) { minute=”00″; }
else if (minute>=15 && minute < 45) { minute=”30″; }
else { minute=”00″; hour++; }
hour = time.getHours().toString().length < 2 ? “0”+hour : hour;
while (document.tstest.bis.length > 0) {
document.tstest.bis.options[document.tstest.bis.length-1] = null;
}
var anOption = new Option(hour+”:”+minute, hour+”:”+minute);
document.tstest.bis.options[document.tstest.bis.length] = anOption
// here is problem for times
if i remove times and use time then i will get onyl system time as i need both system time as well as user slect time
for (i=0; i<times.length; i++) {
document.tstest.bis.options
document.tstest.bis.length] = times[i];
}
document.tstest.bis.options.selectedIndex = 0;
}
</script>

as im using PHP for getting the time in both select field
<select name=”von”>
<option selected value=”<?=date(‘H:i’)?>”><? echo (date(‘H:i’)); ?></option>
<? fillDD(0, 0, -1); ?>//i used one function to call hr and min starts from 0 to 23 hrs as well as 0 to 23 min somethign like 08:00
</select>
function fillDD($min, $max, $selected)
{
for($i=$min; $i<24; $i++) {
//$i = sprintf(‘%02d’, $i); # set $i to be padded with a 0’s up to 2 characters
for($j=$max; $j<60; $j+=10) {
$j = sprintf(‘%02d’, $j); # set $j to be padded with a 0’s up to 2 characters
if($i == $selected && $j == $selected) {
print(“<option SELECTED value=’$i:$j’>$i:$j</option>n”);
}
else {
print(“<option value=’$i:$j’>$i:$j</option>n”);
}
}//for($j)
} //for($i)
}

thanks

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @zuzupus spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...