Capturing value entered in textfield of form and using in javascript code

saturn's Avatar, Join Date: Jun 2009
Light Poster
Hello!

I am just a beginnerin javascript,so pls need your help!

I am making a website using html.I need to capture a value from a textfield of one form in a page and use the value in an if-else loop in javascript in another page.
How to capture the value that would be given by any user and use the value to run the loop to display certain information to the user according to the value? And where should I put the script in the head section or the body section?

I have made the form as-

<form action="tariff2.html">
<center><b>Connected load:
<input type="text" name="load" size="30"></b></center>
<center><br><br><br>
<input type="submit" name="Submit" value=" Submit "
onKeyPress="return submitenter(this,event)"> &nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" name="Reset" value=" Reset "></center>

And the script as-

<script type="text/javascript" language="javascript">
var ld = load.value;
if (ld<10)
{
document.write("<b>Consumer's Category: Domestic-A</b>");
}
else if (ld>10 && ld<20)
{
document.write("<b>Consumer's Category: Domestic-B</b>");
}
else
{
document.write("<b>Consumer's Category: Commercial</b>");
}

Any help would be appreciated
0
pradeep's Avatar, Join Date: Apr 2005
Team Leader
You can post via GET and access the query string to get the value in the next page.
0
sriram225's Avatar, Join Date: May 2009
Go4Expert Member
Scripts in <head>
Scripts to be executed when they are called, or when an event is triggered, go in the head section.

If you place a script in the head section, you will ensure that the script is loaded before anyone uses it.

Scripts in <body>

Scripts to be executed when the page loads go in the body section.

Code:
<html>
<head>
<script type="text/javascript">
....
</script>
</head>
<body>
<script type="text/javascript">
....
</script>
</body>


I have Modified ur Code as following save this in notepad as filename with .html extension and open it works!!!!

Code:
<html>
<body>
<script type="text/javascript" language="javascript">

function cload(val)
{
 var ld =val;
if (ld<10)
 {
  document.write("<b>Consumer's Category: Domestic-A</b>");
 }
 else if (ld>10 && ld<20)
 {
  document.write("<b>Consumer's Category: Domestic-B</b>");
 }
 else
 {
  document.write("<b>Consumer's Category: Commercial</b>");
 }
}
</script>
<form action="tariff2.html">
<center><b>Connected load:
<input type="text" name="load" size="30"></b></center>
<center><br><br><br>
<input type="button" name="Submit" value="Submit" onclick=cload(load.value)> 
&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" name="Reset" value=" Reset "></center>
</body>
</html>
0
sriram225's Avatar, Join Date: May 2009
Go4Expert Member
Code:
You can post via GET and access the query string to get the value in the next page.
Yeah ,use attribute method="get" in form and acces that value using name in nxt page
0
sriram225's Avatar, Join Date: May 2009
Go4Expert Member
Quote:
Originally Posted by sriram225 View Post
You can post via GET and access the query string to get the value in the next page.
Yeah ,use attribute method="get" in form and acces that value using name in nxt page
0
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
(1) Why do you repeat your posts ?!

(2) And the above quote is of pradeep, why did you change it to "Originally Posted by sriram225" ??

(3) Would you care to explain what your html code does ? I don't see anything "working" on my FF.
0
sriram225's Avatar, Join Date: May 2009
Go4Expert Member
Code:
 (1) Why do you repeat your posts ?!

(2) And the above quote is of pradeep, why did you change it to "Originally Posted by sriram225" ??

(3) Would you care to explain what your html code does ? I don't see anything "working" on my FF.

Lol....I thought to edit my reply, acidentally made that replies.....Cool KID
0
saturn's Avatar, Join Date: Jun 2009
Light Poster
Thank u