Get value from a javascript function in a php variable -


Then I have this javascript function which is on my page which calculates the date now, I throw the function by fax I want to use the results that are made so that I can insert that variable into a value in the database. The function should be called on page load. I am trying to complete it for the past 4 hours but there is no solution, no suggestions and solutions are welcome.

My JS Code: -

  & lt; Script language = "JavaScript" & gt; // To calculate a local city / local time // // UTC Offset Function of the City is given to Calxack (City, Offset, Seledet, Silbers, Selminets) {// Alert (Settat); // warning (selHours); // warning (selMinutes); // warning (offset); Var str = selDate; Var res = str.split ("/"); // 07,26 / 2014 // 0,1,2 var d = new date (res [2], res [0], res [1], selHours, selMinutes, 0, 0); // Create date object for current location // Warning (D); // var d = new date (); // warning (d); // Convert to MSEC / Add local time zone offset // get UTC time in MSE UTC = d.getTime () + (d.getTimezoneOffset () * 60000); // Create new date object for different city // supply offset ND = new date (UTC + (3600000 * offset)); // return time string returns as nd.toLocaleString (); } Function testTime () {var selDate = document.getElementById ("datepicker") value; Var selHours = document.getElementById ("hours"). value; Var selMinutes = document.getElementById ("min"). value; Var selTimeZone = document.getElementById ("Timezone"). Values; Warning (selDate); Warning (selHours); Warning (selMinutes); Warning (selTimeZone); } & Lt; / Script & gt;  

Use you to allow your JavaScript to communicate with your PHP backend Ajax . This allows you to send information to a PHP file.

To keep it simple, I recommend that you use jQuery, there are two useful methods that you can use and

your javascript (such as, City, offset, celadet, silhers, semiminates); // We are sending information:

SaveTimeToDB.php $ .ajax ('saveTimeToDB.php', {data: {time: timeToSend} // this is an object in which you want to send all the information}} (Function () {// A function that is said is said that if the alert of the AJAX call was successful ('time is saved');}) unsuccessful (function () {// a function called ajax call When the warning of failure is said ('Oh, something went wrong, did not save time');});}); In the 'SaveTimeToDB.php' file you can now access this variable as:

  $ time = $ _GET ['time'];  

Then you should be able to use this variable and insert it into your database.

Be sure to check many variables on this variable, to ensure that you do not have any malicious injection in your DB.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -