/    Sign up×
Community /Pin to ProfileBookmark

Hi,

i am new in javascript. i have some problems, which is described below

i have a combo box. in this combo box we have displayed different city name
like delhi, bangok etc. when the user select the particluar city it automatically
display the month,day,year and time according to city name. eg: when we select the bangok name it diplay the bankog month, day, year and time.

Please let me know how can i solve this type of problem.

Thanks
Rajeev kumar
software engineer

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERJul 15.2008 — Can you post a brief part of your code, just the selection and display parts?
Copy linkTweet thisAlerts:
@KorJul 15.2008 — You may start studying this universal clock example:
<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;script type="text/JavaScript"&gt;
//Universal clock
//Genuine code by Corneliu Lucian "KOR" Rusu corneliulucian[at]gmail[dot]com
var wd=['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
var D=[
['Bucharest',120,60],//city,standard time zone(minutes), DST(minutes)
['Madrid',60,60],
['New York',-300,60],
['Nairobi',180,0]
]
function calc(){
var spans=document.getElementById('zonediv').getElementsByTagName('span')
for(var i=0;i&lt;D.length;i++){
var t=new Date();
t.setTime(t.getTime()+(t.getTimezoneOffset()*60000)+((D[i][1]+D[i][2])*60000));//the zone's time
var Dy=t.getFullYear();
var Dd=t.getDate()&lt;10?'0'+t.getDate():t.getDate();
var Dm=t.getMonth()&lt;10?'0'+(t.getMonth()+1):t.getMonth()+1;
var Dh=t.getHours()&lt;10?'0'+t.getHours():t.getHours();
var Di=t.getMinutes()&lt;10?'0'+t.getMinutes():t.getMinutes();
var Ds=t.getSeconds()&lt;10?'0'+t.getSeconds():t.getSeconds();
var Dz=wd[t.getDay()];
spans[i].firstChild.data=Dh+':'+Di+':'+Ds+' - '+Dz+' '+Dd+'/'+Dm+'/'+Dy;
}
setTimeout('calc()',1000)
}
onload=function(){
var root = document.getElementById('zonediv');
for(var i=0;i&lt;D.length;i++){
root.appendChild(document.createTextNode(D[i][0]+' '))
var sp= document.createElement('span');
sp.appendChild(document.createTextNode(' '));
root.appendChild(sp);root.appendChild(document.createElement('br'))
}
calc();
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id="zonediv"&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

... which I guess it should be easy for you to understand, as you are a software engineer.?
Copy linkTweet thisAlerts:
@kumar_rajeev47authorJul 16.2008 — Hi,

yesterday i got ur mail. you send me the code. in this code you display three country name and there time and year also. but i have different problem. right now i have send you the code which we are currently working on it. in this code we have different city name in a static html combo box. when we click on any city name it display the current time but in this script it does not show me the current year,day and month. if possible you can edit the code and gave me some solutions.

My code is as follows:


<CENTER>

<FORM NAME="formname">

<SELECT NAME="theirzone">

<OPTION VALUE="4">Abu Dhabi

<OPTION VALUE="9.5">Adelaide

<OPTION VALUE="-9">Alaska

<OPTION VALUE="6">Almaty

<OPTION VALUE="1">Amsterdam

<OPTION VALUE="-7">Arizona

<OPTION VALUE="2">Athens

<OPTION VALUE="12">Aukland

<OPTION VALUE="-1">Azores

<OPTION VALUE="3">Baghdad

<OPTION VALUE="7">Bangkok

<OPTION VALUE="8">Beijing

<OPTION VALUE="1">Berlin

<OPTION VALUE="1">Bern

<OPTION VALUE="-5">Bogota

<OPTION VALUE="5.5">Bombay

<OPTION VALUE="-3">Brasilia

<OPTION VALUE="10">Brisbane

<OPTION VALUE="1">Brussels

<OPTION VALUE="-3">Buenos Aires

<OPTION VALUE="2">Cairo

<OPTION VALUE="5.5">Calcutta

<OPTION VALUE="-4">Canada - Atlantic Time

<OPTION VALUE="-1">Cape Verde Is.

<OPTION VALUE="-4">Caracas

<OPTION VALUE="0">Casablanca

<OPTION VALUE="8">Chongqing

<OPTION VALUE="5.5">Colombo

<OPTION VALUE="9.5">Darwin

<OPTION VALUE="6">Dhaka

<OPTION VALUE="0">Dublin

<OPTION VALUE="2">Eastern Europe

<OPTION VALUE="0">Edingburgh

<OPTION VALUE="5">Ekaterinburg

<OPTION VALUE="-12">Eniwetok

<OPTION VALUE="12">Fiji

<OPTION VALUE="-3">Georgetown

<OPTION VALUE="10">Guam

<OPTION VALUE="7">Hanoi

<OPTION VALUE="2">Harare

<OPTION VALUE="-10">Hawaii

<OPTION VALUE="2">Helsinki

<OPTION VALUE="10">Hobart

<OPTION VALUE="8">Hong Kong

<OPTION VALUE="-5">Indiana (East)

<OPTION VALUE="5">Islamabad

<OPTION VALUE="2">Israel

<OPTION VALUE="2">Istanbul

<OPTION VALUE="7">Jakarta

<OPTION VALUE="4.5">Kabul

<OPTION VALUE="12">Kamchatka

<OPTION VALUE="5">Karachi

<OPTION VALUE="4">Kazan

<OPTION VALUE="3">Kuwait

<OPTION VALUE="-12">Kwajalein

<OPTION VALUE="-4">La Paz

<OPTION VALUE="-5">Lima

<OPTION VALUE="1">Lisbon

<OPTION VALUE="0">London

<OPTION VALUE="5.5">Madras

<OPTION VALUE="1">Madrid

<OPTION VALUE="11">Magadan

<OPTION VALUE="12">Marshall Is.

<OPTION VALUE="10">Melbourne

<OPTION VALUE="-6">Mexico City

<OPTION VALUE="-2">Mid-Atlantic

<OPTION VALUE="-11">Midway Island

<OPTION VALUE="0">Monrovia

<OPTION VALUE="3">Moscow

<OPTION VALUE="4">Muscat

<OPTION VALUE="3">Nairobi

<OPTION VALUE="11">New Caledonia

<OPTION VALUE="5.5">New Delhi

<OPTION VALUE="-3.5">Newfoundland

<OPTION VALUE="9">Osaka

<OPTION VALUE="1">Paris

<OPTION VALUE="8">Perth

<OPTION VALUE="10">Port Moresby

<OPTION VALUE="1">Prague

<OPTION VALUE="2">Pretoria

<OPTION VALUE="3">Riyadh

<OPTION VALUE="1">Rome

<OPTION VALUE="-11">Samoa

<OPTION VALUE="9">Sapporo

<OPTION VALUE="-6">Saskatchewan

<OPTION VALUE="9">Seoul

<OPTION VALUE="8">Singapore

<OPTION VALUE="11">Solomon Is.

<OPTION VALUE="3">St. Petersburg

<OPTION VALUE="1">Stockholm

<OPTION VALUE="10">Sydney

<OPTION VALUE="8">Taipei

<OPTION VALUE="5">Tashkent

<OPTION VALUE="4">Tbilisi

<OPTION VALUE="-6">Tegucigalpa

<OPTION VALUE="3">Tehran

<OPTION VALUE="-8">Tijuana

<OPTION VALUE="9">Tokyo

<OPTION VALUE="-6">US & Canada - Central Time

<OPTION VALUE="-5">US & Canada - Eastern Time

<OPTION VALUE="-7">US & Canada - Mountain Time

<OPTION VALUE="-8">US & Canada - Pacific Time

<OPTION VALUE="8">Urumqi

<OPTION VALUE="1">Vienna

<OPTION VALUE="10">Vladivostok

<OPTION VALUE="4">Volgograd

<OPTION VALUE="1">Warsaw

<OPTION VALUE="12">Wellington

<OPTION VALUE="9">Yakutsk

</SELECT>

<INPUT TYPE="TEXT" SIZE="30" NAME="theirtime" style="border:0">

</FORM>

</CENTER>

<SCRIPT LANGUAGE="JavaScript">

<!--

function padout(number) { return (number < 10) ? '0' + number : number; }

var time = new Date();

function padout(number) { return (number < 10) ? '0' + number : number; }

function ampm(time)

{

var hours = time.getHours(), minutes = padout(time.getMinutes()),seconds = padout(time.getSeconds());

var adjhours = (hours == 0) ? 12 : ((hours < 13) ? hours : hours-12);

return ((adjhours < 10) ? ' ' : '') + adjhours + ':' + minutes + ':'+ seconds + ((hours < 12) ? ' AM' : ' PM');
}


if ((navigator.appVersion.indexOf('MSIE 3') == -1))

var fiddle = 1;

else

var fiddle = -1;

function updateForm() {


var time = new Date();



var TimezoneOffset = time.getTimezoneOffset();
var gmtX = document.formname.theirzone.options[document.formname.theirzone.selectedIndex].value - 0;


time.setTime(time.getTime() + TimezoneOffset*fiddle*60*1000 + gmtX*60*60*1000);

document.formname.theirtime.value = ampm(time);


setTimeout("updateForm()",500);

}

updateForm();

//--></SCRIPT>

Thanks & Regards,

Rajeev kumar
Copy linkTweet thisAlerts:
@KorJul 16.2008 — Hi,

yesterday i got [COLOR="Blue"]ur[/COLOR] mail. [COLOR="Blue"]you[/COLOR] send me the code. in this code [COLOR="Blue"]you[/COLOR] display three country name and there time and year also. but i have different problem. right now i have send [COLOR="Blue"]you[/COLOR] the code which we are currently working on it.[/QUOTE]

And you are talking [COLOR="Blue"]with[/COLOR]...?
Copy linkTweet thisAlerts:
@kumar_rajeev47authorJul 16.2008 — Hi,

i have send u the code. now i want to display the month,year and day when the user click on any city name. for eg: when we click on the bangok it display the time but it does not display the month,year and day of bangkok. this is the problem i am talking about. please help me it very urgent


Thanks & Regards,

Rajeev kumar
Copy linkTweet thisAlerts:
@KorJul 16.2008 — I have not received any mail... Anyway, is this what you need?:
<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="content-type" content="text/html; charset=iso-8859-1"&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;style type="text/css"&gt;
.cities {
cursor:pointer;
margin:6px;
background:#ccc;
color:000;
width:200px;
}
&lt;/style&gt;
&lt;script type="text/javascript"&gt;
//Universal clock
//Genuine code by Corneliu Lucian "KOR" Rusu corneliulucian[at]gmail[dot]com
var setT;
var wd=['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
var D=[
['Bucharest',120,60],//city, standard time zone(minutes), DST(minutes)
['Madrid',60,60],
['New York',-300,60],
['Nairobi',180,0],
['Londra',0,60]
]
function calc(i){
var output=document.getElementById('showT');
var t=new Date();
t.setTime(t.getTime()+(t.getTimezoneOffset()*60000)+((D[i][1]+D[i][2])*60000));//the zone's time
var Dy=t.getFullYear();
var Dd=t.getDate()&lt;10?'0'+t.getDate():t.getDate();
var Dm=t.getMonth()&lt;9?'0'+(t.getMonth()+1):t.getMonth()+1;
var Dh=t.getHours()&lt;10?'0'+t.getHours():t.getHours();
var Di=t.getMinutes()&lt;10?'0'+t.getMinutes():t.getMinutes();
var Ds=t.getSeconds()&lt;10?'0'+t.getSeconds():t.getSeconds();
var Dz=wd[t.getDay()];
output.firstChild.data=Dh+':'+Di+':'+Ds+' - '+Dz+' '+Dd+'/'+Dm+'/'+Dy;
setT=setTimeout(function(){calc(i)},1000);
}
function preCalc(){
setT?clearTimeout(setT):null;
var i=this.ind;
calc(i);
}
onload=function(){
var root = document.getElementById('zonediv');
for(var i=0;i&lt;D.length;i++){
var div= document.createElement('div');
div.ind=i;
div.className='cities';
div.appendChild(document.createTextNode(D[i][0]));
div.onclick=preCalc;
root.appendChild(div);
}
}
&lt;/script&gt;

&lt;/head&gt;

&lt;body&gt;
&lt;div id="zonediv"&gt;&lt;/div&gt;
&lt;br&gt;
&lt;div id="showT"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
×

Success!

Help @kumar_rajeev47 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...