Go4Expert

Go4Expert (http://www.go4expert.com/)
-   JavaScript and AJAX (http://www.go4expert.com/forums/javascript/)
-   -   Capturing value entered in textfield of form and using in javascript code (http://www.go4expert.com/forums/capturing-value-entered-textfield-form-t17832/)

saturn 2Jun2009 12:58

Capturing value entered in textfield of form and using in javascript code
 
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? :confused:

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

pradeep 2Jun2009 14:26

Re: Capturing value entered in textfield of form and using in javascript code
 
You can post via GET and access the query string to get the value in the next page.

sriram225 2Jun2009 17:04

Re: Capturing value entered in textfield of form and using in javascript code
 
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>


sriram225 2Jun2009 17:08

Re: Capturing value entered in textfield of form and using in javascript code
 
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

sriram225 2Jun2009 17:08

Re: Capturing value entered in textfield of form and using in javascript code
 
Quote:

Originally Posted by sriram225 (Post 48846)
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

SaswatPadhi 2Jun2009 17:36

Re: Capturing value entered in textfield of form and using in javascript code
 
(1) Why do you repeat your posts ?! :mad:

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

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

sriram225 2Jun2009 21:07

Re: Capturing value entered in textfield of form and using in javascript code
 
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

saturn 4Jun2009 12:28

Re: Capturing value entered in textfield of form and using in javascript code
 
Thank u :)


All times are GMT +5.5. The time now is 14:19.