473,382 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

use PC time in a dropdown list

Hi, I need some help with time. I have a dropdown list that shows various times so the user can select the time most relevant to their needs, but the system pre-selects the current time


Expand|Select|Wrap|Line Numbers
  1. <%
  2. Dim MyTime    : MyTime     = FormatDateTime(now, 3) 'returns current date/time
  3. %>
  4.  
  5.     <tr>
  6.         <td class="body" align="right"><strong>Select Time In:</strong></td>
  7.         <td>
  8.             <select name="customer_arrivaltime">
  9.     <option selected="selected" value="<%=MyTime%>"><%=MyTime%></option>
  10.             <option value="05:30:00 AM">5:30 AM</option>             <option value="05:45:00 AM">5:45 AM</option>
  11.             <option value="06:00:00 AM">6:00 AM</option>            <option value="06:15:00 AM">6:15 AM</option>
  12.             <option value="06:30:00 AM">6:30 AM</option>            <option value="06:45:00 AM">6:45 AM</option>
  13.             <option value="07:00:00 AM">7:00 AM</option>            <option value="07:15:00 AM">7:15 AM</option>
  14.             <option value="07:30:00 AM">7:30 AM</option>            <option value="07:45:00 AM">7:45 AM</option>
  15.  
  16.         <option value="8:00:00 PM">8:00 PM</option>        
  17.             </select>        
  18.         </td>        
  19.     </tr>
This works great, except that I was an idiot and set it up to use the server time. The server is in the central time zone, now I have users on the east coast so the current pre-selected time is wrong. Bah.


So, I need to use the time on the users PC. It does not need to be atomically accurate, I don’t mind if the users PC has the wrong time. I have been playing with this javascript

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. var newtime;
  3. var d = new Date();
  4. newtime = d.toLocaleTimeString();
  5. document.write(newtime);
  6. </script>
it produces the time in the format I want, but I can't figure out how to get the (newtime) results to appear in my dropdown so the user still sees their current time first.

can someone help? is there a better way to do this?


TIA
Path
May 22 '09 #1
4 2915
GazMathias
228 Expert 128KB
Check out the JavaScript add() method for the Select Object.

http://www.javascriptkit.com/jsref/select.shtml
May 25 '09 #2
ok, so i red up on this option and have spent a lot of time fiddling with it to no avail. so far i have used this
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. var newtime;
  3. var d = new Date();
  4. newtime = d.toLocaleTimeString();
  5.  
  6.  
  7. var myselect=document.getElementById("customer_arrivaltime")
  8. myselect.options[0]=new Option("Here Now", "who", "defaultSelected", "selected") //replace 1st option with a new one
  9.  
  10. </script> 
  11.  
to add an entry "Here now" to the top of my dropdown. but i cant figure out how to display the local PC time "newtime = d.toLocaleTimeString();" in the list.

please help before i go completely bald on this.
May 29 '09 #3
GazMathias
228 Expert 128KB
Hi,

This works for me in IE and Chrome. Doesn't insert the option as the first one, but rather makes it selected:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type = "text/JavaScript">
  4. function addTimeOption()
  5. {
  6.  
  7. var myselect = document.myform.myselect;
  8. var thetime;
  9. var d = new Date();
  10. thetime = d.toLocaleTimeString();
  11.  
  12. var newOptn = document.createElement("OPTION");
  13. newOptn.text = "Here Now";
  14. newOptn.value = thetime;
  15. newOptn.selected = true;
  16. myselect.options.add(newOptn);
  17. }
  18. </script>
  19.  
  20. </head>
  21. <body onLoad="addTimeOption(); ">
  22. <form name = "myform">
  23. <select name="myselect">
  24. <option>Existing option</option>
  25. </select>
  26. <input type="submit" onClick="alert(document.all.myselect.options[document.all.myselect.selectedIndex].value)">
  27. </body>
  28. </html>
  29.  
Function is called on <body onLoad>

Hope that is of some use

Gaz.
Jun 1 '09 #4
Gaz, that worked fantastic, thank you very much for your time and help!
Jun 4 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Joseph Barron | last post by:
Here is a SIMPLE problem that I'm trying to solve. It works in Netscape 6.2, but IE6 gives ""No such interface supported." Below are page1.htm and page2.htm . In page1.htm, there are two...
2
by: Steve Miller | last post by:
hello... i am a 'user' of access, meaning, i import excel files, join, and merge....that's about the extent of my expertise with ms-access. my boss wants me to create an access application that...
2
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
3
by: er1 | last post by:
Hi all, I have created a double dropdown list. Based on the first list selection, second list populates (this works fine). I have a submit button, which when clicked should run a select query...
6
by: yasodhai | last post by:
Hi, I used a dropdown control which is binded to a datagrid control. I passed the values to the dropdownlist from the database using a function as follows in the aspx itself. <asp:DropDownList...
0
by: Andrus | last post by:
I'm using WinForms DataGridView I need to make dropdown list wider that grid column width. I tried the following code, but dropdown list widht is the same as column width. How to increase...
3
by: fish919 | last post by:
Hello All, I am creating a date base in access. I want to create a dropdown list box that is connected to another dropdown list box. You start with a dropdown list that has 5 choices and each of...
5
by: abhi3211 | last post by:
i am using java inside java script page. in that page i want to use two dropdown list. in first dropdown list i am getting data from ms-access database. in second dropdown list i want to get data...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.