By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,462 Members | 799 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,462 IT Pros & Developers. It's quick & easy.

How to get value from JavaScript function

P: 1
Expand|Select|Wrap|Line Numbers
  1. /*This is time counter -it will update every minute
  2. I want to get the value from javascript and save it to database?
  3. */
  4.  
  5. <form name="myForm" method="post">
  6.  
  7. <script type="text/javascript"> 
  8. var num = 0;
  9. function IncCounter() { 
  10. num = num + 1;   // increment counter by 2
  11. document.myForm.counter.value = num;
  12. t = setTimeout('IncCounter()', 600);   // run once per minute
  13.  
  14.  
  15. </script>
  16.  
  17. <?
  18. $conn=mysql_connect("localhost","root","root") or die("Cannot connect to server");
  19. mysql_select_db("test",$conn) or die("cannot select database");
  20.  
  21. echo "<input name=\"counter\" type=\"text\" onFocus=\"IncCounter()\"> " //how save this value to database?
  22. echo "<label id=\"counter\" onfocus=\"IncCounter()\"> </label>" //how to get the value and view as label
  23. ?>
  24. </form>

hope all senior here could help
Jan 4 '12 #1
Share this Question
Share on Google+
1 Reply


100+
P: 1,059
create a hidden type input field in the form

and in the IncCounter function set the hidden field value with the incremented value. by the way, your label tag will never get focus, as far i can recall...
Jan 4 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.