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>
<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>

Duh,

Sorry Paul,

You already answered my question, closing brace.

I did it, and it worked!

I owe you a beer!

Dave

When loading the page, there is an “unexpected end of input” error.

Looking at your script, it seems that a closing brace is missing.

Hey Paul,

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

Dave