wrathican Posted October 1, 2007 Share Posted October 1, 2007 hey there. im REALLY new to JS. ive worked with PHP quite a bit and i seem to know what im doing with it. i made a form where the user could select a date, it had day, month and year dropdown menu's. i used a PHP while statement to create the list of days and i have seen you can do this with JS. the month name was displayed and it had a value called maxday which determined how many days was in the month. the only problem with this is that it had to refresh the page to make the amount of days appear and i hear that JS doesnt do that. i will post the code to do the date selection and if you could give me an idea of how to do it in JS that would be awesome <?php $month = $_POST['month']; $year = $_POST['year']; $dayp = $_POST['day']; if ($month == "Jan" or $month == "Mar" or $month == "May" or $month == "Jul" or $month == "Aug" or $month == "Oct" or $month == "Dec" or $month == ""){$maxday = 31;} if ($month == "Feb") {$maxday = 28;} if ($month == "Feb" && $year == "2008" or $year == "2012") {$maxday = 29;} if ($month == "Apr" or $month == "Jun" or $month == "Sep" or $month == "Nov") {$maxday = 30;} ?> <select name="day"> <option> </option> <?php $day = 1; while($day<=$maxday) { if($dayp == $day) { echo "<option selected>" . $day . "</option>"; }else{ echo "<option>" . $day . "</option>"; } $day++; } ?> </select> <select name="month" onchange=form2.submit()> <?php if($month == "") { echo "<option selected> </option>"; }else{ echo "<option> </option>"; } if($month == "Jan") { echo "<option selected>Jan</option>"; }else{ echo "<option>Jan</option>"; } if($month == "Feb") { echo "<option selected>Feb</option>"; }else{ echo "<option>Feb</option>"; } if($month == "Mar") { echo "<option selected>Mar</option>"; }else{ echo "<option>Mar</option>"; } if($month == "Apr") { echo "<option selected>Apr</option>"; }else{ echo "<option>Apr</option>"; } if($month == "May") { echo "<option selected>May</option>"; }else{ echo "<option>May</option>"; } if($month == "Jun") { echo "<option selected>Jun</option>"; }else{ echo "<option>Jun</option>"; } if($month == "Jul") { echo "<option selected>Jul</option>"; }else{ echo "<option>Jul</option>"; } if($month == "Aug") { echo "<option selected>Aug</option>"; }else{ echo "<option>Aug</option>"; } if($month == "Sep") { echo "<option selected>Sep</option>"; }else{ echo "<option>Sep</option>"; } if($month == "Oct") { echo "<option selected>Oct</option>"; }else{ echo "<option>Oct</option>"; } if($month == "Nov") { echo "<option selected>Nov</option>"; }else{ echo "<option>Nov</option>"; } if($month == "Dec") { echo "<option selected>Dec</option>"; }else{ echo "<option>Dec</option>"; } ?> </select> <select name="year" onChange=form2.submit()> <?php if($year == "") { echo "<option selected> </option>"; }else{ echo "<option> </option>"; } if($year == 2007) { echo "<option selected>2007</option>"; }else{ echo "<option>2007</option>"; } if($year == 2008) { echo "<option selected>2008</option>"; }else{ echo "<option>2008</option>"; } if($year == 2009) { echo "<option selected>2009</option>"; }else{ echo "<option>2009</option>"; } ?> its a rather long and stupid code. i know it can be simplified so if you have any idea please can you help me out Quote Link to comment Share on other sites More sharing options...
fenway Posted October 1, 2007 Share Posted October 1, 2007 You mean like a datepicker? Quote Link to comment Share on other sites More sharing options...
wrathican Posted October 1, 2007 Author Share Posted October 1, 2007 i guess..? but not like ive seen, it just needs to be 3 drop down menus where the maximum amoun of values changes depending on what year and month it is. Quote Link to comment Share on other sites More sharing options...
fenway Posted October 1, 2007 Share Posted October 1, 2007 i guess..? but not like ive seen, it just needs to be 3 drop down menus where the maximum amoun of values changes depending on what year and month it is. Why? It's much more difficult to validate dates that way. 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.