View Full Version : OnFocus Input Problems
rctshine
06-26-2006, 12:31 AM
Okay. Here is my problem. I have 3 input fields. When the first field reaches 5 characters (either through typing or pasting) I need it to immediately go disabled and set the focus to the next field. I'm at my wits end. I have tried everything I can think of. ._. Any help?
TJ_Tigger
06-26-2006, 05:41 AM
I would use the OnKey event to count the number of characters that are being typed into the input object. If that number is greater than or equal to 5 then set focus to the next one and disable the previous one.
HTH
Tigg
Roboblue
06-26-2006, 10:36 AM
you can use the Input Properties-Input Style-Input Mask Options to set the number and type of characters that can be typed into the Input Object. This way, you don't have to disable the input object as it will not allow more than x amount of characters to be entered, and it can still be edited by the user in case of a mistake.
Read the Input Mask help on how to set the characters.
Roboblue
06-26-2006, 10:52 AM
here's a way to step through the inputs
Page On Show
Input.SetEnabled("Input1", true);
Input.SetEnabled("Input2", false);
Input.SetEnabled("Input3", false);
Page.SetFocus("Input1");
Page.StartTimer(300);
Page On Timer
sFocus = Page.GetFocus();
if sFocus == "Input1" then
IN1 = Input.GetText("Input1");
nIN = String.Length(IN1);
if nIN >= 5 then
Input.SetEnabled("Input1", false);
Input.SetEnabled("Input2", true);
Page.SetFocus("Input2");
end
elseif sFocus == "Input2" then
IN2 = Input.GetText("Input2");
nIN = String.Length(IN2);
if nIN >= 5 then
Input.SetEnabled("Input2", false);
Input.SetEnabled("Input3", true);
Page.SetFocus("Input3");
end
elseif sFocus == "Input3" then
IN3 = Input.GetText("Input3");
nIN = String.Length(IN3);
if nIN >= 5 then
Input.SetEnabled("Input3", false);
---put final action here
end
end
rctshine
06-26-2006, 01:42 PM
I would use the OnKey event to count the number of characters that are being typed into the input object. If that number is greater than or equal to 5 then set focus to the next one and disable the previous one.
HTH
Tigg
I did try that. The problem is, the serials have capitalized letters, and the shift key messes things up severely.
rctshine
06-26-2006, 02:38 PM
here's a way to step through the inputs
Page On Show
Input.SetEnabled("Input1", true);
Input.SetEnabled("Input2", false);
Input.SetEnabled("Input3", false);
Page.SetFocus("Input1");
Page.StartTimer(300);
Page On Timer
sFocus = Page.GetFocus();
if sFocus == "Input1" then
IN1 = Input.GetText("Input1");
nIN = String.Length(IN1);
if nIN >= 5 then
Input.SetEnabled("Input1", false);
Input.SetEnabled("Input2", true);
Page.SetFocus("Input2");
end
elseif sFocus == "Input2" then
IN2 = Input.GetText("Input2");
nIN = String.Length(IN2);
if nIN >= 5 then
Input.SetEnabled("Input2", false);
Input.SetEnabled("Input3", true);
Page.SetFocus("Input3");
end
elseif sFocus == "Input3" then
IN3 = Input.GetText("Input3");
nIN = String.Length(IN3);
if nIN >= 5 then
Input.SetEnabled("Input3", false);
---put final action here
end
end
Thanks, that code works well. But now I have another problem. I'm trying to create error messages for events when something goes wrong (for example, when the fields are blank), and then if nothing goes wrong, its supposed to concat the 3 fields values together into one string. Here is my problem:
strs5 = Input.GetText("Input1");
if(strs5==nil)then
Label.SetVisible("Label5", true);
Image.SetVisible("Image6", true);
Application.ExitScript();
end
Now, that SHOULD stop it from executing further if the first field is blank (which it is). The problem is, its not working.
Even though the first field is blank, it continues on to the next line:
strCode = strs1.."-"..strs2.."-"..strs3;
And then gives me an error about the third field being nil (oddness).
Any help with this insanely confusing problem? :huh
Roboblue
06-26-2006, 02:59 PM
look here
strs5 = Input.GetText("Input1");
if(strs5==nil)then
strs5 is a string variable, so it cant be nil. Blank (no characters/text) is ""
try
strs5 = Input.GetText("Input1");
if strs5 == "" then
Intrigued
06-26-2006, 04:17 PM
I have a sample project here:
http://www.amsuser.com/ams/examples/InputLimitInput-AMS6-Intrigued.apz
The code in the project is as follows:
------------------------------[[ SCRIPT: Page: Page1, Event: On Show Script ]]------------------------------
01 Page.SetFocus("Input1")
------------------------------[[ SCRIPT: Page: Page1, Object: Input1, Event: On Key Script ]]------------------------------
strInput1Data = Input.GetText("Input1")
numInputLength = String.Length(strInput1Data)
if numInputLength == 5 then
Input.SetEnabled("Input1", false)
Page.SetFocus("Input2")
end
------------------------------[[ SCRIPT: Page: Page1, Object: Input2, Event: On Key Script ]]------------------------------
strInput1Data = Input.GetText("Input2")
numInputLength = String.Length(strInput1Data)
if numInputLength == 5 then
Input.SetEnabled("Input2", false)
Page.SetFocus("Input3")
end
------------------------------[[ SCRIPT: Page: Page1, Object: Input3, Event: On Key Script ]]------------------------------
strInput1Data = Input.GetText("Input3")
numInputLength = String.Length(strInput1Data)
if numInputLength == 5 then
Input.SetEnabled("Input3", false)
Page.SetFocus("Input1")
end
This works for me even if CAPS are used in the Input objects.
(code: shown is via forum member TJ-TIGGER's IR Project Reviewer program)
Intrigued
06-26-2006, 04:21 PM
To optimize the code and even make an easy-to-use Function, check out using the built-in this in the AMS 6 Help file.
rctshine
06-26-2006, 04:42 PM
Thanks, intrigued. That code worked well.
Thanks to everyone for helping me learn more about AMS6! XD
Intrigued
06-26-2006, 09:15 PM
Your welcome rctshine.
TJ_Tigger
06-27-2006, 08:24 AM
(code: shown is via forum member TJ-TIGGER's IR Project Reviewer program)
Cool I am not the only one who uses it; :D :D :D
Powered by vBulletin™ Version 4.0.6 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.