Solved

Get Javascript results into a hidden field or php variable

Posted on 2010-11-25
2
479 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
2 Comments
 
LVL 10

Accepted Solution

by:
hosneylk earned 250 total points
Comment Utility
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
Comment Utility
<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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now