473,395 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

JavaScript autopopulate a text box

8
I have a JSP page which has two text boxes.
I would like to be able to enter a number into the first textbox, and to have that number automatically appear in the second textbox multiplied by 3.
So if I enter number 1 into the first text box, then I want number 3 appear in the second text box.
Does anyone know how to do that? Do I need to use JavaScript for that?

Thank you!
Oct 25 '07 #1
8 7670
Ferris
101 100+
hi

yes,you do need javascript...

here's the code I write for you:


[HTML]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<script language="javascript">
function mul()
{
var a = document.getElementById("first").value;
document.getElementById("second").setAttribute("va lue",a * 3);
}
</script>
<body>
<input type="text" id="first" onChange="mul();" value="0" />
<input type="text" id="second" value="0" />
</body>
</html>


[/HTML]
Oct 25 '07 #2
jambyl
8
Ferris,
Thank you for such a quick reply!!! You code works good, but right now after typing a number in my first text box - I have to click somewhere or hit TAB, Only then the second text box is multiplied by three.
Is there a way to have the number in second text box change without me leaving the first box?

Kind regards.
Oct 25 '07 #3
Ferris
101 100+
hi

change line 16 :
<input type="text" id="first" onChange="mul();" value="0" />

into

<input type="text" id="first" onKeyUp="mul();" value="0" />
Oct 25 '07 #4
jambyl
8
Ferris,
This works great!!!

Thank you!!!
Oct 25 '07 #5
hi

change line 16 :
<input type="text" id="first" onChange="mul();" value="0" />

into

<input type="text" id="first" onKeyUp="mul();" value="0" />
Don't do that Ferris! IE doesn't support key events, use a setInterval every few seconds to fill er up.
Oct 26 '07 #6
Ferris
101 100+
Don't do that Ferris! IE doesn't support key events, use a setInterval every few seconds to fill er up.

thanks for telling me that,but I have tested my code in both IE and Firefox,they works well.
Oct 26 '07 #7
acoder
16,027 Expert Mod 8TB
Don't do that Ferris! IE doesn't support key events, use a setInterval every few seconds to fill er up.
What makes you say that? Can you give an example that doesn't work?
Oct 29 '07 #8
What makes you say that? Can you give an example that doesn't work?
Sorry I guess it does. I think it's IE6 that doesn't support. Maybe just starting to have nightmares about IE :p
Dec 28 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Dave | last post by:
Hi folks, I'm in the middle of adding some validation functionality to an inventory tracking form. What I would like to do is have one dropdown menu/Listbox(Part Number) and another text...
3
by: Eric | last post by:
Hi, I'm just looking into the samples that are delivered withthe Enterprise Localization Framework/Toolkit. I have set it up and it all works fine. But.. now i have a question. I read a...
0
by: guy | last post by:
I am experimenting with the Enterprise Localization Toolkit. Using the Designer and Translator feature, I am able to include a new label in the Basic sample. Apparently, this can also be...
3
by: russr | last post by:
Hi, I need to autopopulate a second field based on the info that i have selected from a drop down box in the first field. I need to write both fields back to a SQL database... EXAMPLE: Field A...
5
by: aharding | last post by:
I would like to autopopulate fields in a form by choosing one value from a table and having the corresponding data filled in based on 'Library' tables I have made. I have been successful in building...
4
by: PRLIT | last post by:
First, let me just say that I've been looking at this site for help for awhile now. Thank you for all the help you given me over the past few months. Second, I'm creating a form in Access 2007. I...
2
by: jw01 | last post by:
I have a form in which there is one combo box and three text boxes: Combo Box: -> Item A -> Item B -> Item C TextBox1: TextBox2: ...
6
by: GLEberts | last post by:
Hi, I would like to ask for some direction on what would be the best way to (1) Autopopulate a combo box to text boxes - used for a customer list (2) Then have the information saved in the...
3
by: hkim8392126 | last post by:
I've been searching and reading the forum, but with no success to find what I was looking for. I am trying to autopopulate a field in a form. I am not sure if I need to create a query or table to do...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.