Home: Other Programming Languages: Javascript:
Capturing value entered in textfield of form and using in javascript code



saturn
New User

Jun 2, 2009, 2:57 AM


Views: 34685
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?

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


santhosh_89
Novice

Jun 2, 2009, 9:33 PM


Views: 34680
Re: [saturn] Capturing value entered in textfield of form and using in javascript code

 Way -1
Once posting the value to next form,to store the POST method values to the hidden box,Actually there you will be running a java script,Now you will be able to access the hidden boxes,So you can get the value,But it is not security way,
Way -2
You can access paret and top methods to get the distance form values,
Example:
parent.Docuemnt.GetElementById('field_name').value;

If there any difficult call me....


(This post was edited by santhosh_89 on Jun 2, 2009, 9:35 PM)