Lisawynn
03-02-2004, 09:32 PM
fyi - newbie
I need to create a page that accepts numbers entered by a user - a starting number, an ending number and a number to increment by - and onclick of a button, displays the information on a new page. The user can enter either positive or negative numbers. If the starting and ending numbers are the same, the user is alerted that their number selections are invalid. The part I am having difficulty with is getting the text box values submitted by the user to be used for the counter value. What it looks like to me is that instead of converting the variable "a" for example to a number, it is concatenating the string and just adding the value of text6 together i.e.5+5+5+5 to come up with 555555. The script goes on forever and locks your machine so don't run it. The following is what I currently have:
<html>
<script language="javascript">
function displaynumbers(){
var a
a=document.form4.text4.value
var b
b=document.form4.text5.value
var c
c=document.form4.text6.value
if(document.form4.text4.value==document.form4.text5.value)
{
alert("Your number selections are invalid.")
}
for(counter=a;counter<b;counter=counter+c)
{
document.write((counter+"<br/>"))
}
}
</script>
<body>
<form name=form4>
<p align=center>10 marks</p>
1. Have the user type in the first box a number to start counting from.<br>
2. Have the user type in the second box a number where to stop counting to.<br>
3. Have the user type in a number to step up or down by when counting.<br>
<li type=disc>When the user presses the button this page will clear and the list of numbers will be displayed<br>
<li type=disc>If the user uses the same starting and ending number alert them that is not valid.<br>
<li type=disc>The user can enter a starting number bigger than the ending number.<br>
<li type="disc">Take into account that a user might enter a positive or negative step value<br>
<p align=center>
starting number <input type="text" name="text4"> 
ending number<input type="text" name="text5">
<p align=center>step up by<input type="text" name="text6"> 
<input type="button" name="display" value="Display Numbers" onClick="displaynumbers()">
</body>
</html>
Thanks for any assistance/guidance.
I need to create a page that accepts numbers entered by a user - a starting number, an ending number and a number to increment by - and onclick of a button, displays the information on a new page. The user can enter either positive or negative numbers. If the starting and ending numbers are the same, the user is alerted that their number selections are invalid. The part I am having difficulty with is getting the text box values submitted by the user to be used for the counter value. What it looks like to me is that instead of converting the variable "a" for example to a number, it is concatenating the string and just adding the value of text6 together i.e.5+5+5+5 to come up with 555555. The script goes on forever and locks your machine so don't run it. The following is what I currently have:
<html>
<script language="javascript">
function displaynumbers(){
var a
a=document.form4.text4.value
var b
b=document.form4.text5.value
var c
c=document.form4.text6.value
if(document.form4.text4.value==document.form4.text5.value)
{
alert("Your number selections are invalid.")
}
for(counter=a;counter<b;counter=counter+c)
{
document.write((counter+"<br/>"))
}
}
</script>
<body>
<form name=form4>
<p align=center>10 marks</p>
1. Have the user type in the first box a number to start counting from.<br>
2. Have the user type in the second box a number where to stop counting to.<br>
3. Have the user type in a number to step up or down by when counting.<br>
<li type=disc>When the user presses the button this page will clear and the list of numbers will be displayed<br>
<li type=disc>If the user uses the same starting and ending number alert them that is not valid.<br>
<li type=disc>The user can enter a starting number bigger than the ending number.<br>
<li type="disc">Take into account that a user might enter a positive or negative step value<br>
<p align=center>
starting number <input type="text" name="text4"> 
ending number<input type="text" name="text5">
<p align=center>step up by<input type="text" name="text6"> 
<input type="button" name="display" value="Display Numbers" onClick="displaynumbers()">
</body>
</html>
Thanks for any assistance/guidance.