JagvsShodan
04-28-2006, 03:07 AM
I'm very new to JavaScript and am faced with the problem of making a function that declares an array of five numbers. Initialize the five values from textboxes in a form. Using a for loop, sum the elements of the array and display the result on the web page when the submit button is clicked. that will take.
here is what I have ... I hope it isn't way off:
<script type="text/javascript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
var n = new Array();
n[0] = parseInt(document.form[0].num1.value);
n[1] = parseInt(document.form[0].num2.value);
n[2] = parseInt(document.form[0].num3.value);
n[3] = parseInt(document.form[0].num4.value);
n[4] = parseInt(document.form[0].num5.value);
function numbers() {
for (var count = 0; count < 4; ++count) {
var answer = answer + n[count];
document.write(answer);
}
}
//STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>
<form>
<p>Insert a number in each text space and click "submit."</p>
<input type="text" name="num1">
<input type="text" name="num2">
<input type="text" name="num3">
<input type="text" name="num4">
<input type="text" name="num5">
<input type="button" value="Submit" onclick="numbers();" />
</form>
any help with this?
thanks
here is what I have ... I hope it isn't way off:
<script type="text/javascript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
var n = new Array();
n[0] = parseInt(document.form[0].num1.value);
n[1] = parseInt(document.form[0].num2.value);
n[2] = parseInt(document.form[0].num3.value);
n[3] = parseInt(document.form[0].num4.value);
n[4] = parseInt(document.form[0].num5.value);
function numbers() {
for (var count = 0; count < 4; ++count) {
var answer = answer + n[count];
document.write(answer);
}
}
//STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>
<form>
<p>Insert a number in each text space and click "submit."</p>
<input type="text" name="num1">
<input type="text" name="num2">
<input type="text" name="num3">
<input type="text" name="num4">
<input type="text" name="num5">
<input type="button" value="Submit" onclick="numbers();" />
</form>
any help with this?
thanks