SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  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

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    When loading the page, there is an "unexpected end of input" error.

    Looking at your script, it seems that a closing brace is missing.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Paul,

    Thanks for your reply! Sorry I'm extremely new to javascript. Where should the missing brace go?

    Dave

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

    Sorry Paul,

    You already answered my question, closing brace.

    I did it, and it worked!

    I owe you a beer!

    Dave


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
  •