Java and HTML

Associate
Joined
21 Jan 2006
Posts
2,171
Location
Seaham, Co. Durham
Ok this might sound basic, but i'm trying to learn javascript. I set myself a challenge to make a function which returns the product of two numbers, i have managed to write the function as follows

Code:
<html>

<head>
<script type="text/javascript">
function product(x,y)
{
return x*y
}
</script>

<script type="text/javascript">
document.write(product(5,9))
</script>
</head>

<body>

</body>

</html>

What i would like to know is, how do i call the function with two values that have been entered into text boxes on the html page, instead of the hard coded 5 and 9?
 
Soldato
Joined
18 Oct 2002
Posts
8,997
Location
London
Code:
<html>

<head>
<script type="text/javascript">
function product()
{
var x = document.getElementById("x").value;
var y = document.getElementById("y").value;
document.write(x*y);
}
</script>


</head>

<body>

<form onsubmit="product()">
	<input type="text" name="x" id="x" />
	<input type="text" name="y" id="y" />
	<input type="submit" name="submit" />
</form>

</body>

</html>

Something like that would work, to a certain extent!
 
Back
Top Bottom