JavaScript - Javascript Drop Down Date Pick
can someone give me the code to display drop down date with default todays date selected...format dd/mm/yyyy
i found the code to display month in mon format..what is to be modified to get in mm format here ______________ <script> var monthtext=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec']; function populatedropdown(dayfield, monthfield, yearfield){ var today=new Date() var dayfield=document.getElementById(dayfield) var monthfield=document.getElementById(monthfield) var yearfield=document.getElementById(yearfield) for (var i=0; i<31; i++) dayfield.options[i]=new Option(i, i+1) dayfield.options[today.getDate()]=new Option(today.getDate(), today.getDate(), true, true) //select today's day for (var m=0; m<12; m++) monthfield.options[m]=new Option(monthtext[m], monthtext[m]) monthfield.options[today.getMonth()]=new Option(monthtext[today.getMonth()], monthtext[today.getMonth()], true, true) //select today's month var thisyear=today.getFullYear() for (var y=0; y<20; y++){ yearfield.options[y]=new Option(thisyear, thisyear) thisyear+=1 } yearfield.options[0]=new Option(today.getFullYear(), today.getFullYear(), true, true) //select today's year } </script> Similar TutorialsHi there, I am trying to pick the larger of 5 numbers and sometimes there is a tie. I would like to prioritize variable c1 if there is a tie. This data is from a quiz I am writing. var c1 = 2; // Takes priority if there is a tie. var c2 = 1; var c3 = 2; var c4 = 0; var c5 = 0; Not sure if this is possible in javascript: I'm looking for two different dates (bill date and due date) on an invoice that are captured by OCR. If one of them exists, but the other does not, I want the empty field to be 14 days before (or after) the other. For example: if the bill date is 7/27/2010 and the due date was not captured, I want to set the due date as 8/10/2010 (14 days after the bill date). If the due date was captured as 8/10/2010, but the due date is blank, I want to assign the bill date as 7/27/2010 (14 days before the due date). if both dates have values, do nothing. Thanks. Hi I saw on a site one drop down list and i wanted to make it auto change. I mean i have this list in my database and everytime i need to change the date manually. Is it possible that these dates changes every day it display as below but it auto change with day.? and not have Saturday and Sunday in them. Thanks for any help : PHP Code: <select name = "date" value="<?php echo "$date" ?>" id = "date" STYLE="width: 200px; border:1px solid #4088b8; color:#111111; font-family:Arial; background:#ffffff;"> <option value="0" >Please Select</option> <option value="02/11/2009 - Monday" >02/11/2009 - Monday</option> <option value="03/11/2009 - Tuesday" >03/11/2009 - Tuesday</option> <option value="04/11/2009 - Wednesday" >04/11/2009 - Wednesday</option> <option value="05/11/2009 - Thursday" >05/11/2009 - Thursday</option> <option value="06/11/2009 - Friday" >06/11/2009 - Friday</option> <option value="07/11/2009 - Monday" >09/11/2009 - Monday</option> <option value="08/11/2009 - Tuesday" >10/11/2009 - Tuesday</option> <option value="09/11/2009 - Wednesday" >11/11/2009 - Wednesday</option> <option value="10/11/2009 - Thursday" >12/11/2009 - Thursday</option> <option value="11/11/2009 - Friday" >13/11/2009 - Friday</option> <option value="14/11/2009 - Monday" >16/11/2009 - Monday</option> <option value="15/11/2009 - Tuesday" >17/11/2009 - Tuesday</option> <option value="16/11/2009 - Wednesday" >18/11/2009 - Wednesday</option> <option value="17/11/2009 - Thursday" >19/11/2009 - Thursday</option> <option value="18/11/2009 - Friday" >20/11/2009 - Friday</option> <option value="21/11/2009 - Monday" >23/11/2009 - Monday</option> <option value="22/11/2009 - Tuesday" >24/11/2009 - Tuesday</option> <option value="23/11/2009 - Wednesday" >25/11/2009 - Wednesday</option> <option value="24/11/2009 - Thursday" >26/11/2009 - Thursday</option> <option value="25/11/2009 - Friday" >27/11/2009 - Friday</option> <option value="28/11/2009 - Monday" >30/11/2009 - Monday</option> <option value="29/11/2009 - Tuesday" >01/12/2009 - Tuesday</option> <option value="30/11/2009 - Wednesday" >02/11/2009 - Wednesday</option> <option value="01/12/2009 - Thursday" >03/12/2009 - Thursday</option> <option value="02/12/2009 - Friday" >04/12/2009 - Friday</option> </select> Best Wishes I have a date of birth drop down for 'Day', 'Month' and a text field for Year. How can I get the select value of the drop down and year text field into a single text field, separated by '-'? The single text field would need to update if someone changed the drop down / year selections. Hope someone can help - I'm stumped! Hi folks, i am trying to generate a dynamic datefield with date mask "mm/dd/yyyy" and trying to insert it into Oracle db ...i still got the error ORA invalid month ehich means the date filed is not recognized as date: below is what i am doing : newStartDate = document.createElement( 'INPUT' ); newStartDate.setAttribute('type','Date'); newStartDate.setAttribute('id1','id'+ elementid+elementrow); newStartDate.setAttribute('name','StartDateName'+ elementid+elementrow); newStartDate.size=8; newStartDate.style.backgroundColor= bgc; any help thanks ?? Also i want to add a datepicke to this textbox..how it is posible / other option is to use Jquery datepicker but could not know how to impement it thanks again Hi, greeting all. could you help me please to edit this javascript, I'd like to add a message alert if the values stopped on (777) Live Demo Code: <script language="JavaScript"> function begin() { i=0; document.form.col1.value="V"; document.form.col2.value="V"; document.form.col3.value="V"; roll(speed); } function roll(speedB) { if (document.form.col1.value=="V") { document.form.a1.value=Math.floor(Math.random()*9) +0 ; } if (document.form.col2.value=="V") { document.form.a2.value=Math.floor(Math.random()*9)+0 ; } if (document.form.col3.value=="V") { document.form.a3.value=Math.floor(Math.random()*9)+0 ; } timerid=setTimeout("roll("+speedB+")",speedB); } function stop(col) { if ( col==1) if(document.form.col1.value!=" "){ document.form.col1.value=" ";i++;} if ( col== 2) if(document.form.col2.value!=" "){ document.form.col2.value=" ";i++;} if ( col==3) if(document.form.col3.value!=" "){ document.form.col3.value=" ";i++;} // speedB=500000;roll(speedB); } </script> My array contains 15 value I want to random pick 5 value: Code: myArray[0] ="a"; myArray[1] ="b"; myArray[2] ="c"; myArray[3] ="d"; myArray[4] ="e"; myArray[5] ="f"; myArray[6] ="g"; myArray[7] ="h"; myArray[8] ="i"; myArray[9] ="j"; myArray[10] ="k"; myArray[11] ="l"; myArray[12] ="a"; myArray[13] ="b"; myArray[14] ="c"; How to random pick from all elements with no repeat of the same content. e.g. if myArray[0] is picked then myArray[12] will not be picked again. (because they have the same value "a") Basically I want to factor a number and select the two closest numbers to the middle of the factors for example: 20 factors to 1, 2, 4, 5, 10, 20 I want it to return 4 and 5 If the number is has an odd number of factors (has to be a perfect square) I want it to select the middle number and say it twice for example: 64 factors to 1, 2, 4, 8, 16, 32, 64 I want it to return 8 and 8 Would I use an array or what? My code should probably look like: PHP Code: x = //Factors array y = //number of items in x if (/*y is even*/){ i = y/2 i2 = i+1 a = [i] b = [i2] } else{ i = //somehow the center number? i2 = i a = [i] b = [i2] } how can I get 1 tenth of a second for my clock? (bad typo for clock. I had to edit it. I'm saying that for the admin because I know you're not suppose to edit excessively)
Hi, My JS Date validation was failing for a date which as per business is a valid date (01/01/0001) - MM/DD/YYYY It seems that the constructor for Date object is doing something funny.. var dayobj = new Date(yearfield, monthfield-1, dayfield) wasn't working for this case whereas teh one mentioned below seems to be working fine : var dayobj = new Date() dayobj.setFullYear(yearfield,monthfield-1,dayfield) What's the trick here ?? I cannot get my JavaScript code to work. Does anyone know what I am doing wrong with the following code: <html> <head> <title>Welcome</title> </head> <body> <h1>Welcome to my Web Page</h1> <script type="text/javascript"> /* <![CDATA[ */ var dateObject = new Date(); var greeting = ""; var curTime = ""; var minuteValue = dateObject.getMinutes(); var hourValue = dateObject.getHours(); if (minuteValue < 10) minuteValue = "0" + minuteValue; if(hourValue < 12) { greeting = "<p>Good morning! " curTime = hourValue + ":" + minuteValue + " AM"; } else if (hourValue == 12) { greeting = "<p>Good afternoon! "; + minute Value + " PM"; } else if (hourValue == 17) { greeting = "<p>Good afternoon!" cutTime = (hourValue-12) + ":" + minuteValue + " PM" } else { greeting = "<p>Good evening! " curTime = (hourValue-12) + ":" + minuteValue + " PM" } var dayArray = newArray("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); var monthArray = newArray("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); var day = dateObject.getDay(); var month = dateObject.getMonth(); document.write("<p>"+ greeting + "It is " + curTime + " on " + dayArray[day] + ", " + monthArray[month] + " " + dateObject.getDate() + ", " + dateObject.getFullYear() + ".</p>"); /* ]]> */ </script> </body> </html> ~xhtml205 In my JSP page i have start date and End date fields are there. The format for these two fields has Date and Time . But my requirement is if i change the date in start date field it should change the same date in End Date field also automatically. Here is my code Code: <div id=apptTimeEditOD style="display:<%=appt.allday()?"none":"block" %>; padding: 4px 4px 4px 4px; position: absolute; width: 90; height: 22; left: 85; top: 2; text-align: left;"> <%=_r.drawDatePicker( _ahsPage, "startDate", appt.getApptDate() ) %> <select name="startHour" id=startHour class="selInputSmall" onChange="odRefreshApptEndTime();"> <%= OptionMenu.render( _ahsPage, "CAL_TIME_HOUR", appt.getStartTime().substring(0,2), false, true ) %> </select> <select name="startMin" id=startMin class="selInputSmall" onChange="odRefreshApptEndTime();"> <%=OptionMenu.render( _ahsPage, "CAL_TIME_MINUTE", appt.getStartTime().substring(3,5), false )%> </select> </div> <div class="formPrompt" style="position: absolute; width: 90; height: 22; left: 20; top: 2; text-align: left;"><%=_pCal.get("end_time")%>:</div> <div id=apptTimeEditEnD style="display:<%=appt.allday()?"none":"block" %>; padding: 4px 4px 4px 4px; position: absolute; width: 90; height: 22; left: 85; top: 2; text-align: left;"> <%=_r.drawDatePicker( _ahsPage, "startDate", appt.getApptDate() )%> <div id=apptODEndTime style="position: absolute; width: 90; height: 22; left: 140; top: 2; text-align: left;" > </div> </div> Please give me an idea on this one ? How do i change the End Date automatically when i change the start date. Hello. I have got this kind of array: Code: $days = array('Monday' => '2012-03-19', 'Tuesday' => '2012-03-20' ); I'm iterating like this: Code: foreach($days as $key => $value){ echo '<a href="javascipt:confirmDelete('.$value.');">Delete</a>'; } Script: Code: function confirmDelete(day) { if (confirm('Delete?')) { window.location.href = 'processDay.php?action=delete&day=' + day ; } } While i hover over the link with coursor, it show it good: javascript:confirmDelete(2012-03-19), but when I submit the delete confirmation, i get &day=1987. Where is the problem? I hope someone out there can help me! I am a librarian and am looking for a way to get javascript to display a simple future date for books we need to pull off our shelf. The date needs to be 6 days into the future. I want the date to display as either a hyphenated number: ie. 8-13 (for August 13th) or as an abbreviation of the month with the future date: ie. Aug. 13 I've tried this a number of ways, but I am just not getting the simple date format that I want. I need the script to automatically account for number of days in the month, etc. and adjust accordingly. For instance, if it was July 31st, I would want the script to display Aug. 6 or 8-6. I am not well-versed when it comes to javascript (read ignorant), but I posted below what I have managed to cobble together after searching online and playing with the ww3 school's "TryitEditor". Thanks for any help or tips in advance! Script below displays: PULL DATE: 6 days, on Saturday, August 13, 2011 Thanks! but I want it to display: PULL DATE: 6 days, on Aug. 13 or 6 days, on 8-13 Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en-GB"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>HOLD pull date</title> </head> <body> <form name="myFormName" method="get" action=" "> <h1>PULL DATE:</h1> <noscript><div>Javascript must be enabled in your browser</div></noscript> <script type="text/javascript"> var myDelayInDays=6; var myDate=new Date(); var oneDayInMilliseconds = (24*60*60*1000); var myTimeInMillisconds=myDate.getTime()+(myDelayInDays * oneDayInMilliseconds); myDate.setTime(myTimeInMillisconds); /* setTime() is an 'inbuilt' javascript function that calculates a date and time by adding or subtracting a specified number of milliseconds to/from midnight January 1, 1970 it can be buggy in some browsers */ var widgetDueDate = myDate.toLocaleDateString(); /* toLocaleDateString() is an 'inbuilt' javascript function that converts a Date object, according to local time, to a string and returns the date portion */ document.write('<p>' + myDelayInDays + ' days, on <strong>' + widgetDueDate + '<\/strong><\/p>'); </script> </form> <p>Thanks!</p> </body> </html> hello i have this code: Code: Code: function buildMonthlyEntries() { var startDate = new Date(document.getElementById('startDate').value); var endDate = new Date(document.getElementById('endDate').value); if(startDate == "Invalid Date" || endDate == "Invalid Date") { return null; } var entryCount = endDate.getMonth() - startDate.getMonth(); var monthlyEntries = document.getElementById('monthlyEntries'); monthlyEntries.innerHTML = ""; for(var i = 0; i < entryCount; i++) { var textElement = document.createElement('input'); textElement.setAttribute('type', 'text'); textElement.setAttribute('id', 'entry' + i); monthlyEntries.appendChild(textElement); } return null; } <div id="dateRange"> <input type="text" id="startDate"> <input type="text" id="endDate"> </div> <div id="monthlyEntries"></div> <INPUT TYPE="button" NAME="button" Value="Click" onClick="buildMonthlyEntries()"> It calculates the number of months between the 2 dates and generates the number of input filds equal to the number of months. The only problem is when i change the year. For example if i have start date 2012-03-22 and enddate 2013-04-22, instead of generating 13 input fields it only generates 1 field, because it only substracts months. How can i make this script also calculate corectly months even if year is changed? Thanks Hi guys. I'm trying to make a small bit of scripting that will show the current time, updating once every second. What I need is the following: 1. Multiple timezones or GMT offsets (just put me on the right path, I can code them in, 2. Daylight savings time taken into consideration (only for Australia), adding the 1 hour during the times it is needed, 3. Text to show "Open" and "Closed" during different times (open during 8am to 5pm and closed if not 8am to 5pm.) I have the following code as a start, but I am completely stuck with how to get the rest of what I need! Any help would be appreciated. <h4>Victoria <script type="text/javascript"> <!-- var currentTime = new Date() var hours = currentTime.getHours() var minutes = currentTime.getMinutes() if (minutes < 10){ minutes = "0" + minutes } document.write(hours + ":" + minutes + " ") if(hours > 11){ document.write("PM") } else { document.write("AM") } //--> </script> <script type="text/javascript"> <!-- var currentTime = new Date() var hours = currentTime.getHours() var minutes = currentTime.getMinutes() if (minutes < 10){ minutes = "0" + minutes } if(hours > 11){ document.write("True") } else { document.write("False") } //--> </script> </h4> Cheers in advance. Dale. I am trying to use JavaScript in conjuntion with html to display a table of sortable cities, states and dates. The dates are my problem. I am a novice and was given this code. But it seems to sort in European style, yyyy/mm/dd. I need it to sort mm/dd/yyy, which i am told is US style. Any help on this, I would be most grateful for. I have placed a page here to let you see the code at work. This page has the code on it in text also. I do not mind posting the code hgere also if you prefer. Thanks for any help you may be willing to offer me with this. Preston I have created a journey planner from www.transportdirect.com (it automatically creates the code, so you just copy and paste it into your websites HTML code). But it doesn't automatically update the date parts of the form, to match the current date. This is the code for the date part of the form: <td> <p style="font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: left; margin: 5px 5px 5px 5px;"> <select id="dtd" name="dtd" style="border-right: lightgrey 1px solid; border-top: lightgrey 1px solid; font-size: 12px; border-left: lightgrey 1px solid; border-bottom: lightgrey 1px solid; font-family: verdana, arial, helvetica, sans-serif; background-color: white; height: 18px;"> <option value="01">01</option> <option value="02">02</option> <option value="03">03</option> <option value="04">04</option> <option value="05">05</option> <option value="06">06</option> <option value="07">07</option> <option value="08">08</option> <option value="09">09</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select> <!-- !IMPORTANT! Month/year dropdown values will need to be maintained over time. Only the current month and the following two months should be selectable because complete public transport data is only available for journeys up to three months in the future. Client-side script should be added to default the dropdown values to the current date and time. --> <select id="dtm" name="dtm" style="border-right: lightgrey 1px solid; border-top: lightgrey 1px solid; font-size: 12px; border-left: lightgrey 1px solid; border-bottom: lightgrey 1px solid; font-family: verdana, arial, helvetica, sans-serif; background-color: white; height: 18px;"> <option selected="selected" value="032012">Mar 2012</option><option value="042012">Apr 2012</option><option value="052012">May 2012</option> </select></p> </td> What I want to do is add a javascript code to automatically keep the dates updated? If you need any further details, please ask. Thank you for any help. |