Apologies guys, that should have been a reply to my earlier thread.
On Mar 9, 4:34 pm, "agrath"
<agr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> <html>
> <head>
> <script src="prototype.js"
language="javascript"></script>
> <script src="scriptaculous.js"
language="javascript"></script>
> <script>
> var lastHighlight;
>
> function NumericInput_OnKeyDown(e)
> {
> if (document.all) { e = window.event; }
> var key;
> if (e.keyCode) key = e.keyCode;
> if (e.which) key = e.which;
> if (key != undefined) {
> var srcElement = Event.element(e)
> debug(srcElement.id + " -> " + key + "
-> " +
> String.fromCharCode(key));
> var validationType =
srcElement.getAttribute("validationtype");
> debug(validationType);
> var dp = 0;
> if (srcElement.value.lastIndexOf(".") != -1) dp
>
srcElement.value.substr(srcElement.value.lastIndexOf(".")+1).length +
> 1;
> debug(dp);
> if (validationType == ''currency''
&& dp > 2) //if we are validating a
> currency field, we need to check it''s length of decimal places
> if (key<8||key>9) //if not tab/backspace
> if (!(key >= 35 && key <= 40)
&& key != 46) //if not arrows,
> home, end, delete
> failedValidation(e,key,srcElement);
> if (key<8||key>9) //if not tab/backspace
> if (!(key >= 35 && key <= 40)
&& key != 46) //if not arrows, home,
> end, delete
> if (key<48||key>57||e.shiftKey) //if not a
number and
> shift not pressed (symbols)
> if ((validationType != "decimal"
&& validationType!= "currency")
> || (validationType == ''decimal'' && key == 190
&& !
> srcElement.value.toArray().select(function (c) { return
> c=="."; }).length == 0) || (validationType ==
''decimal'' && key != 190)
> || (validationType == ''currency'' && key == 190
&& !
> srcElement.value.toArray().select(function (c) { return
> c=="."; }).length == 0) || (validationType ==
''currency'' && key !> 190))
> failedValidation(e,key,srcElement);
> }}
>
> function failedValidation(e,key,srcElement)
> {
> Event.stop(e);
> if (lastHighlight) lastHighlight.cancel();
> if (key >= 20) lastHighlight = new Effect.Highlight(srcElement,
> { duration: .5,
>
startcolor:"#ff9999",endcolor:"#ffffff",restorecolor:"#ffffff"});
> debug("invalid key: " + key);
> return;}
>
> function debug(text)
> {
> new Insertion.Top("debuggingoutput",text +
"<br/>");}
>
> function Begin()
> {
> debug("onload called");
> $A(document.getElementsByTagName("INPUT")).each(function
(input) { if
> (input.type == "text" &&
input.getAttribute("validationtype") != null)
> { debug("observer added to " + input.id); Event.observe(input,
> "keydown", NumericInput_OnKeyDown, true); } });}
>
> </script>
> </head>
> <body onload="Begin();">
> <strong>Numeric Only:</strong> <input
type="text"
> id="IntegerOnlyInputControl_1" size="40"
validationtype="numeric"></
> input><br/>
> <strong>Decimal:</strong> <input
type="text"
> id="DecimalOnlyInputControl_1" size="40"
validationtype="decimal"></
> input><br/>
> <strong>Currency:</strong> <input
type="text"
> id="CurrencyOnlyInputControl_1" size="40"
validationtype="currency"></
> input><br/>
> <strong>Anything:</strong> <input
type="text"
> id="AnyTextInputControl_1"
size="40"></input><br/>
> <br/><br/>
> <strong>Debugging</strong>
> <div id="debuggingoutput" style="width:600px;
height:400px;
> border:solid 1px #000000; padding-right:25px; overflow: auto;">
> </div>
> </body>
> </html>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---