Solved

Get Javascript results into a hidden field or php variable

Posted on 2010-11-25
2
480 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

895 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

12 Experts available now in Live!

Get 1:1 Help Now