Jump to content

How to convert a php function into a javascript function


astratt

Recommended Posts

How do would I convert this php function into a js function?

function getWeeks(){
$day = date('N'); // numeric representation of the day of the week
if ($day == 1) // today is Sunday, so let the range begin with today
$n = 0;
else //today is not Sunday, so set the range to begin from the last Sunday
$n = -$day;

echo "<select name='dates'>";
$string .= '<option value="null" selected="true">Select a Value</option>';
for ($i = 0; $i < 4; $i++) {
// add each week to the list
echo "<option value=\"". date("m/d/Y", mktime(0,0,0,date("m"), date("d") + $n + 1, date("y"))) . " - " . date("m/d/Y", mktime(0,0,0,date("m"), date("d") + ($n + 7), date("y"))) ."\">" . date("m/d/Y", mktime(0,0,0,date("m"), date("d") + $n + 1, date("y"))) . " - " . date("m/d/Y", mktime(0,0,0,date("m"), date("d") + ($n + 7), date("y"))) . "</option>";
$n += 7;
}
echo "</select>";
}

 

If anyone could help that would be great. Ultimately these values are generated on the fly but after the value is selected I need to insert them into the database field. If you don't understand just ask me to clarify. Just remember the first thing I need to do is convert this php function to javascript. Which is what I really would like to know how to do first.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.