A problem I have ran into though is how to prevent a form from submitting if it fails one of the validation methods. I know how returning false to the form on submission will do the trick but I am simply not sure how to do that with in the current form of my script.
Here is a small chunk of my code.
Expand|Select|Wrap|Line Numbers
- FC = function(id){
- var _id = document.getElementById(id);
- return {
- on: function (evt,fnc,useCapture)
- {
- obj = _id;
- if (!useCapture) {
- useCapture = false;
- }
- if (obj.addEventListener){
- obj.addEventListener(evt,fnc,useCapture);
- return true;
- }
- else if (obj.attachEvent) {
- return obj.attachEvent("on"+evt,fnc);
- }
- },
- alphaOnly: function()
- {
- // check for alpha characters only
- return this;
- },
- minLength: function()
- {
- // check for minimum length
- return this;
- },
- formatNum: function()
- {
- // format a number text field
- return this;
- }
- };
- };
- // The following code is how it would be used in its current form.
- FC('form1').on('submit',function(){
- FC('input1').minLength('3').alphaOnly();
- });
Obviously this script won’t be very useful unless I can get it to actually stop a form from submitting so if someone could provide some insight into this that’d be great.