Solved

Get Javascript results into a hidden field or php variable

Posted on 2010-11-25
2
487 Views
Last Modified: 2012-05-10
Dear Experts,

I have found a very nice javascript script that detects users timezone. The javascript calculates the timezone and then checks the results again a select menu, to display the correct timezone.

It is not perfect but for my purposes it works well. What I need it to put the javascript into a hidden form field or create a variable from the results from the timezone.js so I can then insert into my DB.

I do not know javascript at all and I do not even know were to begin. I have included the two files. index.html that has the select menu and the timezone.js which does the calculation.

     index.html detect-timezone.js

Many thanks as always
0
Comment
Question by:Lightwalker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
hosneylk earned 250 total points
ID: 34215798
add a hidden field

e.g.
<input id="hfTimeZone" type="hidden" />

in the js file add this line

document.getElementById('hfTimeZone').value = convert(std_time_offset)+","+dst;

above this line..
if (document.getElementById('timezone')) {
0
 
LVL 6

Expert Comment

by:brb6708
ID: 34215808
<script type=text/javascript>
function timezonefunction() {
    result= .... do something ...;
    document.getElementById('MyHiddenField').innerHTML = "<input type='hidden' name='somename' value=result />
}
</script>
</head>
   
<body onLoad=timezonefunction()>
<form name="some_name" action="new_url">
<div id=MyHiddenField></div>
.....

You can place a div box with an id and modify that div box using javascript as shown in above example.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question