i have 2 test input boxes and a button on a card.
field price
field ans
a button has this code
on mouseUp
if price is an integer
put "Yes" into ans
else
put "no" into ans
endif
end mouseUp
when I click the button nothing happens
Testing a field for valid number
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Testing a field for valid number
In your example code "ans" isn't accompanied by an object reference, and so is being treated like a variable.
To put a value into a field, include the "field" object specifier, e.g.:
put "SomeValue" into field "ans"
To put a value into a field, include the "field" object specifier, e.g.:
put "SomeValue" into field "ans"
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Testing a field for valid number
Hi trags3,
you are using price and ans like variables, but tehy are in fact fields!
So you need to tell LC this fact
Best
Klaus
you are using price and ans like variables, but tehy are in fact fields!
So you need to tell LC this fact

Code: Select all
on mouseUp
if fld "price" is an integer then
put "Yes" into fld "ans"
else
put "no" into fld "ans"
## END IF are 2 words!
## Wrong: endif
end if
end mouseUp
Klaus
Re: Testing a field for valid number
Richard & Klaus
Thanks a lot. That works fine.
Tom
Thanks a lot. That works fine.
Tom
Re: Testing a field for valid number
Hi Tom,
From the users side of things you should be checking while they enter characters into the field not after.
In the field script
That will allow for decimal points and "$" but not letters. Make sure in the fields inspector you have "tab on return" selected.
Simon
From the users side of things you should be checking while they enter characters into the field not after.
In the field script
Code: Select all
on keyDown tkey
if tKey is not a number and tKey is not in ".$" then
answer "Please enter numbers only"
else
pass keyDown
end if
end keyDown
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!