V
viola823
Hi
I have a simple code where I try to change a global variable by the
function run by a button with 'onClick' event, but my solution won't
work... here's the code:
---------------------------
<html>
<head>
<script language="JavaScript">
var v = 0;
function change_v() {
v++;
}
function show_v() {
alert(v);
}
</script>
</head>
<body>
<form method="post">
<input type="button" name="b1" value="change_v()"
onClick="change_v();">
<input type="button" name="b2" value="show_v()" onClick="show_v();">
</form>
<script language="JavaScript">
document.write('v = ' + v);
</script>
</body>
</html>
---------------------------
Here:
<input type="button" name="b1" value="change_v()"
onClick="change_v();">
<input type="button" name="b2" value="show_v()" onClick="show_v();">
variable 'v' is changing and displaing correctly by the functions ,
but here:
document.write('v = ' + v);
'v' all the time equals 0...
What's wrong? Any ideas?
Thanks a lot for any suggestions!
Greets
Ps. sorry for my english
I have a simple code where I try to change a global variable by the
function run by a button with 'onClick' event, but my solution won't
work... here's the code:
---------------------------
<html>
<head>
<script language="JavaScript">
var v = 0;
function change_v() {
v++;
}
function show_v() {
alert(v);
}
</script>
</head>
<body>
<form method="post">
<input type="button" name="b1" value="change_v()"
onClick="change_v();">
<input type="button" name="b2" value="show_v()" onClick="show_v();">
</form>
<script language="JavaScript">
document.write('v = ' + v);
</script>
</body>
</html>
---------------------------
Here:
<input type="button" name="b1" value="change_v()"
onClick="change_v();">
<input type="button" name="b2" value="show_v()" onClick="show_v();">
variable 'v' is changing and displaing correctly by the functions ,
but here:
document.write('v = ' + v);
'v' all the time equals 0...
What's wrong? Any ideas?
Thanks a lot for any suggestions!
Greets
Ps. sorry for my english