473,400 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

changing the value of a js variable through a form button or hyperlink.

Avatar19
Hi,
my question is this: I have a dynamic countdown script in which I can create a countdown on my webpage by passing a string into a countdown function. I have created a variable that deals with each element of the time i.e. month,day,hour,minute,second.
what I want to do is have a button or hyper-link on my page that when pressed will update the timer i.e. add some extra time to it, such as 9 seconds.

So if I have a:
Expand|Select|Wrap|Line Numbers
  1. var month = 'April';
  2. var day = '07';
  3. var year = '2011';
  4. var hour = '11';
  5. var minute = '01';
  6. var second = '00';
  7. var test = month+' '+day+', '+year+' '+hour+':'+minute+':'+second;
  8.  
in my file 'countdown.php'
how do I update this variable by simply clicking on a button or hyper-link.

I have written a basic php script that can do the operation, I just do not know how to implement it cos I am very new with Js.

Expand|Select|Wrap|Line Numbers
  1. function bid($seconds)
  2. {
  3. $seconds = intval($seconds);
  4. $seconds = $seconds+9;
  5. if (strlen($seconds)==1)
  6. {
  7. $seconds = "'0'+seconds"+'';
  8. }
  9. return $seconds;
thank you in advance for any help!!
Apr 6 '11 #1
3 1413
Dormilich
8,658 Expert Mod 8TB
I wouldn’t use PHP for such a trivial matter as JavaScript is able to handle that itself.

what you need to do is assign an event handler to the button or link and inside that do the countdown modification.
Apr 7 '11 #2
ok cool I get that, so if you would not mind helping me with a little syntax and logic, if my js function is:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3.  
  4. <script language="JavaScript" type="text/javascript">
  5.  
  6. function bid(variable){
  7. variable = parseInt(variable)
  8. variable = variable+9
  9. variable = '0'+variable+''
  10. return variable
  11.  
  12. }
  13. var seconds = '00'
  14.  
  15. var execute = bid(seconds)
  16. document.write(execute)
  17.  
  18. </script>
  19. <br>
  20. <a href="tester.php" onClick="execute">Bid</a>
  21. //tester.php is the file name
  22.  
  23.  
  24. </body>
  25. </html>
I am not sure if I understand the logic of how to continually call this function every time the hyper-link is clicked, cos the var seconds does not update, it only gets executed once and then nothing changes.
output given by this is:
09
Bid//hyperlink
Apr 7 '11 #3
Great news I managed to get the timer working correctly, what I now discovered is that I need to create some way so that every time the page gets refreshed the extra seconds that have been added do not get lost.

So, is the best way to do this to store all the date data in my database and call the input for all my functions from there?? Just in case you do not know what I mean , my function that handles the countdown takes in string of format
Expand|Select|Wrap|Line Numbers
  1. var test = month+' '+day+', '+year+' '+hour+':'+minute+':'+second;
so would it be best to store and update that variable in my database???

Thanks for any help.
Apr 13 '11 #4

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

Similar topics

7
by: PhilM | last post by:
perhaps I am just a little tired, but I am having trouble with my form buttons. Firstly I name them like this name=\"round".$counter."heats\" which results in variables $round1heats...
6
by: opt_inf_env | last post by:
Hello, anybody know why the following button <form action="newpage.php?id=3"> <input type="submit" value="Cancel"> </form> loads "newpage.php?" (not "newpage.php?id=3")?
4
by: ry66 | last post by:
Hello All! Is it possible to submit a form using hyperlink? I want to send hidden element when a link is clicked. I read some books, but I found only using button which I don't want to use. ...
4
by: mitch-co2 | last post by:
What I am trying to do is when someone clicks on the YES radio button I want the text field called MYTEXT to equal the text field named DATE. The below code works as long as I do NOT UN-COMMENT...
3
by: opt_inf_env | last post by:
Hi, Is it right that the following code will create a button, which being pressed causes loading a new page (some type of hyper link). <form actioni=new_page.php> <input type="submit"...
0
by: Dave | last post by:
Hi , I have the following where I need to append a string variable inside a hyperlink template, inside a datalist. The variable 'categoryList' is the culprit. No matter where this variable is...
2
by: planetthoughtful | last post by:
Hi All, I have a calendar form that updates a date field on the form from which it was called. I have code in the OnChange event of the date field that I would like performed whenever the date...
7
by: JR123 | last post by:
I need some help. When the user enters a number if there is a match I want it to display as a hyperlink to that specific section of an intranet site we have at work. I have quite a lot of data but...
5
by: plumba | last post by:
Ok, another query.... I have a checkbox at the bottom of my form which when checked unhides a <div> block which displays the submit button. The problem I have is when the clear form button is...
5
by: JohnDriver | last post by:
Hi, I am having a form which has a text box and 3 radio buttons. I am using GET method in Ajax to pass the value. I can pass the value of the textbox fine but how to pass the value of radio...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.