I want to access the value of variable a inside var2() function. However, it gives an error saying the value is not defined.
<html>
<head>
<script type="text/javascript">
function var1(data)
{
var a = data;
}
function var2()
{
var b = a;
alert(b);
}
</script>
</head>
<body>
<a href="#x" class="overlay" onclick="var1(data)"></a>
<input type="button" value="Send" onclick="var2()" />
</body>
</html>
Please anyone help me.
try below code
var a;
function var1(data)
{
a= data;
}
function var2()
{
var b = a;
alert(b);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With