Link to home
Start Free TrialLog in
Avatar of Lightwalker
Lightwalker

asked on

Get Javascript results into a hidden field or php variable

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
ASKER CERTIFIED SOLUTION
Avatar of hosneylk
hosneylk
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bernie Bsen
<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.