help with form auto update

J

John

Hi,

I would like to update my form after something is intered into a textbox in
real time.

For instance, Box A has a blank entry and I enter in 5. Box B I enter in 6
so in Box C it should automatically give me 11 (if the code I put in is to
add box A and B). Then in Box D I put in 3 (say to subtract from A and B
combined) so then Box C adjusts to give me 8.

Don't worry about the math as that's all taken care of it, I just need to be
able to know how to update on the fly like this.

Any help in trying to accomplish this would be appreciated.

Thanks in advance!
john
 
R

RobG

John said:
Hi,

I would like to update my form after something is intered into a textbox in
real time.

For instance, Box A has a blank entry and I enter in 5. Box B I enter in 6
so in Box C it should automatically give me 11 (if the code I put in is to
add box A and B). Then in Box D I put in 3 (say to subtract from A and B
combined) so then Box C adjusts to give me 8.

Don't worry about the math as that's all taken care of it, I just need to be
able to know how to update on the fly like this.

Any help in trying to accomplish this would be appreciated.

Thanks in advance!
john

Add events to the input element onkeyup attribute. A trivial example
follows:


<script type="text/javascript">
function addItems(tot)
{
var t, f=tot.form;
var s=0;
for (var i=1, len=arguments.length; i<len; ++i){
t = f[arguments];
if (t.value && !isNaN(t.value)){
s += +t.value;
}
}
tot.value = s;
}

</script>

<form action="">
<input type="text" name="inp-01"
onkeyup="addItems(this.form['inp-03'],'inp-01','inp-02');"
<input type="text" name="inp-02"
onkeyup="addItems(this.form['inp-03'],'inp-01','inp-02');"
<input type="text" name="inp-03"
onkeyup="addItems(this.form['inp-03'],'inp-01','inp-02');"</form>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top