|
 |
beginning_javascript thread: JavaScript function
Message #1 by "Anita Luff" <aluff@e...> on Tue, 30 Jul 2002 20:31:20
|
|
Hello,
I'm new to JavaScript and I'm trying to write a function to do the
following:
When the user clicks in a textbox a series of prompts allow her to enter 3
values (Words Read, Errors, and Seconds). The function then needs to use
the 3 values in a arithmetic calculation to produce the reading fluency
rate of a student. I've created the function and called it using the
onFocus event. The prompts come up and everything looks fine...except the
resulting value is not appearing in the textbox after the function is
complete. Here's my code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<script language="JavaScript">
function CalcFluencyRate (){
var Words = prompt("Enter the number of words read correctly:", "");
var Errors = prompt("Enter the number of errors:", "")
var Seconds = prompt("Enter the number of seconds to read passage:", "");
var result = ((Words - Errors) * 60)/Seconds;
return result;
}
</script>
<form name="form1" method="post" action="">
<p>
<input type="text" name="txtFluencyRate" onFocus="CalcFluencyRate();">
</p>
</form>
</body>
</html>
Thanks!
Message #2 by <wshbone@m...> on Tue, 30 Jul 2002 19:12:57 -0400
|
|
Anita,
Try adding alert(result); just before the return in your function
Pete
Message #3 by Greg Griffiths <greg2@s...> on Wed, 31 Jul 2002 01:07:02 +0100
|
|
change
return result;
into ;
document.form1.txtFluencyRate.value=result;
At 20:31 30/07/02 +0000, you wrote:
>Hello,
>
>I'm new to JavaScript and I'm trying to write a function to do the
>following:
>
>When the user clicks in a textbox a series of prompts allow her to enter 3
>values (Words Read, Errors, and Seconds). The function then needs to use
>the 3 values in a arithmetic calculation to produce the reading fluency
>rate of a student. I've created the function and called it using the
>onFocus event. The prompts come up and everything looks fine...except the
>resulting value is not appearing in the textbox after the function is
>complete. Here's my code:
>
>
>Thanks!
>
>---
>
>Improve your web design skills with these new books from Glasshaus.
>
>Usable Web Menus
>http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
>r-20
>Constructing Accessible Web Sites
>http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
>r-20
>Practical JavaScript for the Usable Web
>http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
>r-20
Message #4 by pankaj.shinde@i... on Wed, 31 Jul 2002 08:00:39 +0530
|
|
Hi,
In place of writing
"return result;"
Use
document.form1.txtFluencyRate.value=result;
This will solve ur problem.
With Regards,
-Pankaj
-----Original Message-----
From: Anita Luff [mailto:aluff@e...]
Sent: Wednesday, July 31, 2002 2:01 AM
To: Beginning JavaScript
Subject: [beginning_javascript] JavaScript function
Hello,
I'm new to JavaScript and I'm trying to write a function to do the
following:
When the user clicks in a textbox a series of prompts allow her to enter 3
values (Words Read, Errors, and Seconds). The function then needs to use
the 3 values in a arithmetic calculation to produce the reading fluency
rate of a student. I've created the function and called it using the
onFocus event. The prompts come up and everything looks fine...except the
resulting value is not appearing in the textbox after the function is
complete. Here's my code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<script language="JavaScript">
function CalcFluencyRate (){
var Words = prompt("Enter the number of words read correctly:", "");
var Errors = prompt("Enter the number of errors:", "")
var Seconds = prompt("Enter the number of seconds to read passage:", "");
var result = ((Words - Errors) * 60)/Seconds;
return result;
}
</script>
<form name="form1" method="post" action="">
<p>
<input type="text" name="txtFluencyRate" onFocus="CalcFluencyRate();">
</p>
</form>
</body>
</html>
Thanks!
---
Improve your web design skills with these new books from Glasshaus.
Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
r-20
Message #5 by "Anita Luff" <aluff@e...> on Wed, 31 Jul 2002 03:57:12
|
|
Hi Pete and Greg,
Thanks for both suggestions. I tried them and they worked well. Since I need to populate the
input box with the resulting value, Greg's suggestion was really what I'm looking for. Now I
have a followup question. I have 6 input boxes for which I need to call this function. How do I
send the name of the text box as a parameter? I really appreciate the advice.
Anita
> change
return result;
into ;
document.form1.txtFluencyRate.value=result;
At 20:31 30/07/02 +0000, you wrote:
>Hello,
>
>I'm new to JavaScript and I'm trying to write a function to do the
>following:
>
>When the user clicks in a textbox a series of prompts allow her to enter 3
>values (Words Read, Errors, and Seconds). The function then needs to use
>the 3 values in a arithmetic calculation to produce the reading fluency
>rate of a student. I've created the function and called it using the
>onFocus event. The prompts come up and everything looks fine...except the
>resulting value is not appearing in the textbox after the function is
>complete. Here's my code:
>
>
>Thanks!
>
>---
>
>Improve your web design skills with these new books from Glasshaus.
>
>Usable Web Menus
>http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
>r-20
>Constructing Accessible Web Sites
>http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
>r-20
>Practical JavaScript for the Usable Web
>http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
>r-20
Message #6 by Greg Griffiths <greg2@s...> on Wed, 31 Jul 2002 19:45:04 +0100
|
|
you can either pass the name of the field and use it or you can pass a
reference to it using the THIS keyword. If you post some more info we
should be able to guide you in the right direction.
At 03:57 31/07/02 +0000, you wrote:
>Hi Pete and Greg,
>
>Thanks for both suggestions. I tried them and they worked well. Since I
>need to populate the
>input box with the resulting value, Greg's suggestion was really what I'm
>looking for. Now I
>have a followup question. I have 6 input boxes for which I need to call
>this function. How do I
>send the name of the text box as a parameter? I really appreciate the advice.
>
>Anita
>
>
> > change
>
>return result;
>
>into ;
>
>document.form1.txtFluencyRate.value=result;
>
>At 20:31 30/07/02 +0000, you wrote:
> >Hello,
> >
> >I'm new to JavaScript and I'm trying to write a function to do the
> >following:
> >
> >When the user clicks in a textbox a series of prompts allow her to enter 3
> >values (Words Read, Errors, and Seconds). The function then needs to use
> >the 3 values in a arithmetic calculation to produce the reading fluency
> >rate of a student. I've created the function and called it using the
> >onFocus event. The prompts come up and everything looks fine...except the
> >resulting value is not appearing in the textbox after the function is
> >complete. Here's my code:
> >
> >
> >Thanks!
> >
> >---
> >
> >Improve your web design skills with these new books from Glasshaus.
> >
> >Usable Web Menus
> >http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
> >r-20
> >Constructing Accessible Web Sites
> >http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
> >r-20
> >Practical JavaScript for the Usable Web
> >http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
> >r-20
>
>
>
>---
>
>Improve your web design skills with these new books from Glasshaus.
>
>Usable Web Menus
>http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
>r-20
>Constructing Accessible Web Sites
>http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
>r-20
>Practical JavaScript for the Usable Web
>http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
>r-20
|
|
 |