digitalgod Posted August 16, 2006 Share Posted August 16, 2006 hey guys,I was wondering how can I take a day (such as Friday) and transform it into something like this 0000-00-00 (year-month-day)I have a drop down that's being populated with an array like so[code=php:0]list($y,$m,$d) = explode("-",date("Y-m-d"));$daysValue = array();for ($i=0;$i<=6;$i++) { array_push($daysValue,date("l", mktime(0,0,0,$m,$d+$i,$y)));}echo '<select name="night" onchange="Fill_Sub()" style="width:150px; height:17px; font-family:tahoma; font-size:10px; color:#9A400C "><option value="">Select one</option>';for($i=0;$i<count($days);$i++) { echo '<option value='.strtolower($daysValue[$i]).'>'.$daysValue[$i].'</option>';}echo "</select>";[/code]so when the form is submitted I'd like to take that day and transform it into a full date (0000-00-00). I'd normally give it that value in the drop down but I can't do that here because I need the value to be something like Friday.is there a way I can take just take that day and transform it? All the days start from today till the week after like Wednesday to Tuesday. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 17, 2006 Share Posted August 17, 2006 Just put the date you're wanting into the value of the select option:[code]<?phplist($y,$m,$d) = explode("-",date("Y-m-d"));$daysValue = array();for ($i=0;$i<=6;$i++) { $n = mktime(0,0,0,$m,$d+$i,$y); $daysValue[date("Y-m-d", $n)] = date("l", $n);}echo ' <select name="night" onchange="Fill_Sub()" style="width:150px; height:17px; font-family:tahoma; font-size:10px; color:#9A400C "> <option value="">Select one</option>';foreach ($daysValue as $key => $value) { echo ' <option value=' . $key . '>' . $value . '</option>';}echo "</select>";?>[/code] Quote Link to comment Share on other sites More sharing options...
digitalgod Posted August 17, 2006 Author Share Posted August 17, 2006 well that's what I said.... I'd normally do that but I can't, I need the value to be a day because when the user selects a day javascript/php checks to see if that day has subcategories and if it does it populates the 2nd drop down. is there another way? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 17, 2006 Share Posted August 17, 2006 rather than using the value property for the select box, use the text property, which will return the string displayed, rather than the value of the option selected for your javascript function. However, when the script is posted, it should still return the proper value...unless you change it via javascript Quote Link to comment Share on other sites More sharing options...
digitalgod Posted August 17, 2006 Author Share Posted August 17, 2006 ahhh never thought of that, I'll give it a shot and post back Quote Link to comment Share on other sites More sharing options...
digitalgod Posted August 17, 2006 Author Share Posted August 17, 2006 darn it I forgot that the text is different from the value... the drop down looks likeWednesday (Aug 16th) and the value looks like wednesday... I added that so that people don't get confusedhmm any other suggestions? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 17, 2006 Share Posted August 17, 2006 Use the javascript function split to seperate your day display into seperate items...[code]var text = selectedoption.split(" ");var day = text[0];[/code]Something similar to that should work.JS is not that different from PHP, the functions are just a little different, so you can do nearly all the same string manipulations. Quote Link to comment Share on other sites More sharing options...
digitalgod Posted August 17, 2006 Author Share Posted August 17, 2006 thanks hitman, worked perfectly. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.