I need the community to help me with the following:
I defined the variable x=1
in my js file. I have 2 HTML files that use that variable (1.html and 2.html). I want to use onclick
event in 1.html to change the value of variable x
to 2
permanently.. so that if I use x
variable in 2.html it's value is 2
not 1
.
This is what I have in java.js file:
x=1;
This is in 1.html:
<html>
<head>
<script type="text/javascript" src="java.js">
</script>
</head>
<body>
<input type="button" value="Change x" onClick="x=4">
<p id="iz"></p>
</body>
</html>
This is in 2.html:
<html>
<head>
<script type="text/javascript" src="java.js">
</script>
</head>
<body>
<input type="button" value="Change x" onClick="x=x+1">
<p id="iz"></p>
</body>
</html>
The result of the button in 2.html should be 5
.