Inserting a character at the text insertion point in a field

Tore Nilsen tore.nilsen at me.com
Tue Apr 28 15:06:52 EDT 2015


I try to make a script in a field to allow only numbers or the decimal sign to be entered into the field. To block any other key is easy, but I have run into problems when I try to insert the decimal sign at the text insertion point in the field. 

This script only allows me to insert the decimal sign at the end of the string. I seem to be unable to find any help in the lessons on the runner web site or in the dictionary.  Does anyone have a smart solution that I can use to impress my students, and maybe help them in their preparations for their exam?

on keyDown theKey
      if theKey is a number then
      pass keyDown
end if
   if theKey is "." or theKey is "," then
      if the text of me is not empty and "." is not in me then
         put "." after me
      end if
   end if
end keyDown

—

Tore Nilsen


More information about the use-livecode mailing list