Hi, I have started learning javascript yesterday and so got the basics down. But I wanted to get a bit more complicated today, using variable passing with alert boxes etc. So, I wrote the script to pass set variables from one script to another after a button was clicked, and then display it in an alert box.
Well, now I want to make it so the user can choose the variables themselves. So I created a simple HTML form with two input boxes, which was then supposed to be sent to the functions to be multiplied and displayed in the alert box.
Here is what I had:
Code:
<html>
<head>
<script type="text/javascript">
function func_math(x,y)
{
return x*y;
}
</script>
<script type="text/javascript">
function func_alert()
{
alert("The number is " + func_math(2,3));
}
</script>
</head>
<body>
<input type="button" onclick="func_alert()" value="click">
</body>
</html>
So this work perfectly, no problems what so ever. But, now I tried to use a HTML form to allow users to choose the variables, which is easy if I wanted to POST to another page, but I do not, I just want the alert box to display. I have gone through many different versions and used different approaches, tried to use resources but found nothing that helped They had passing variables, even to alert boxes, but they were just text so did not have to be manipulated first.
this is what I have now,
Code:
<html>
<head>
<script type="text/javascript">
function func_math(x,y)
{
return z=x*y;
}
</script>
<script type="text/javascript">
function func_alert()
{
alert("The number is " + func_math(z));
}
</script>
</head>
<body>
<form name="numform" >
x:
<input type="integer" name="x" value="x">
y:
<input type="integer" name="y" value="y">
<input type="submit" value="click" onsubmit="func_alert(x,y)">
</form>
</body>
</html>
Now, the html form displays no probs, but clicking submit just leads to the page being reloaded and no display box appears or even error messages. Can any one give me a hand or point me in the right direction?
Thanks for any help received, Mike