SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Threaded View

  1. #1
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    try to write a script that adds 1 value to a variable everytime a button is clicked

    Hello,

    I am new to javascript. I was trying to do something rather basic. I want to creat a button that when clicked, it will increase the value of a variable by 1. And then if the variable = 1, it will write a= 1 and redirect to a url.

    here's my script, can anyone tell me where I went wrong?

    HTML Code:
    <html>
    <head>
    <script type="text/javascript">
    
    var a=0
    function addToa() {
    	 a=(a + 1)
    	
    if(a==1) {
    	document.write("a="+a)
            window.location="http://"
    }
    
    </script>
    
    
    </head>
    <body>
    
    <div style=" position: absolute; left:80; top: 35;">
    <input type="button" onclick="addToa()" value="Next">
    </div>
    </body>
    <html>
    Last edited by Mittineague; Aug 11, 2011 at 10:23. Reason: reformatting bbcode tags


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •