PDA

View Full Version : Two little textfield related questions



Berryblue
March 17th, 2003, 09:14 AM
I'm working on a simple flash mx application for a school project and I need a little help. I'm fairly new to flash.

Theres an order form where people can input the quantities they want at the bottom there is a total$ box.

Question 1:
How can I get the total displayed to update as the users change the quantities without having to press any accept buttons?
-Currently total is a dynamic text box and the inputs are input text fields

Question 2:
Is there a way to limit what people can type in an input box? I was hoping to make it so the quantity input boxes would only allow you to type numbers.

Any help would be much appreciated.

Thank you

kode
March 17th, 2003, 09:50 AM
Question 1:
the attached file should solve the problem ;)

Question 2:
hmmm .. no idea :-\
i'll let know if i think of a solution :)

kode
March 17th, 2003, 10:38 AM
could anybody please simplify this mess ? :P

o = function() {
for (i=0; i<this.length; i++) {
this.text.charAt(i) == "0" || this.text.charAt(i) == "1" || this.text.charAt(i) == "2" || this.text.charAt(i) == "3" || this.text.charAt(i) == "4" || this.text.charAt(i) == "5" || this.text.charAt(i) == "6" || this.text.charAt(i) == "7" || this.text.charAt(i) == "8" || this.text.charAt(i) == "9" ? c.text = Number(a.text)+Number(b.text) : this.text = 0;
}
}
a.text = b.text = c.text = 0;
a.onChanged = this.o;
b.onChanged = this.o;

Berryblue
March 17th, 2003, 02:11 PM
Thank you very much Kax thats perfect. :)

I'll have to try the code snipit you wrote for the numbers but you really seem to know what your doing :)

kode
March 17th, 2003, 02:18 PM
well thanks :)

i'll try to clean the code later .. ;)

kode
March 17th, 2003, 04:19 PM
i'll try to clean the code later .. ;)
a promisse kept =)

o = function() {
for (i=0; i<this.length; i++) {
!isNaN(this.text.charAt(i)) ? c.text=Number(a.text)+Number(b.text) : r();
}
}
r = function() {
a.text = b.text = c.text = 0;
}
r();
a.onChanged = this.o;
b.onChanged = this.o;

eyezberg
March 18th, 2003, 03:13 AM
why not just use "restrict"?
as in myTextfield.restrict="1234567890";
one line instead of a function... :-)

kode
March 18th, 2003, 03:37 AM
why you didn't say that before!!? :P
ok .. sometimes you just overlook the most easiest things :-\