Solved

Get Javascript results into a hidden field or php variable

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

This article discusses four methods for overlaying images in a container on a web page
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

860 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