By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,471 Members | 732 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,471 IT Pros & Developers. It's quick & easy.

help with form auto update

P: n/a
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
Jan 4 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
John wrote:
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[i]];
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>

--
Rob
Jan 5 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.