Show edited variable
Posted: Tue Jan 19, 2010 4:06 am
Hi. I'm new to Javascript, and am trying to use it for form validation. My code is:
Then on the actual page i have:
Now my problem is that it does not show anything for the variable 'b' (because it is set to "" when the page is loaded). Do i need to reload the page to be able to show the value for b? How would i do this?
Thanks
Code: Select all
<script type="text/javascript">
var b = "";
function checkNumber()
{
var a = document.getElementById('amount').value
if(isNaN(a))
{
b = "Value must be a number";
}
}
</script>Code: Select all
<input type="text" name="amount" id="amount" onchange="checkNumber()"/>
<script type="text/javascript">
document.write(b);
</script> Thanks