3
<script language="JavaScript"> function calcTime(offset) { d = new Date(); utc = d.getTime() + (d.getTimezoneOffset() * 60000); nd = new Date(utc + (3600000*offset)); return "The local time is " + nd.toLocaleString(); } alert(calcTime('-8')); alert(calcTime('-7')); alert(calcTime('-6')); alert(calcTime('-5')); </script> 

'In this I have 4 alerts to show timezone's time and date.and at every load of page it shows all 4 alerts... but i want to show the value of alerts in textbox with dropdown selection. i have 4 drop down values Pacific, Mountain, Central And Eastern timezone. I want to show result value in textbox on dropdown selection. Please help to solve this problem. '

1
  • Here's the Pseudocode .. you need to create a listener for your dropdown menu.. after that condition the selected value on what timezone it belongs.. get the value and display in textbox. :) Commented Jan 30, 2015 at 6:27

1 Answer 1

1

Hope this is what you ask for:

<select name="timezone" onChange="calcTime(this.value)">

Update

Javascript:

<script language="JavaScript"> function calcTime(offset) { d = new Date(); utc = d.getTime() + (d.getTimezoneOffset() * 60000); nd = new Date(utc + (3600000*offset)); document.getElementById('result').value=nd.toLocaleString(); } </script> 

HTML:

<input type="text" name="result" id="result" value="">

Sign up to request clarification or add additional context in comments.

1 Comment

What is the UI result of this code ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.