Home Downloads Documents Contact

 

Introduction

Simbel JavaScript Generator creates for you a javascript code form validation from XML config file. This method is an easy way to keep your configuration of your HTML forms and change params easy.

An example of this configuration may be:

<simbelmyne>
        <config>
                <param name="create-form" value="yes" />
        </config>
        <form name="formulario">
                <form-element name="username" type="text" accepted-chars="alpha">
                        <errors>
                                <error type="onmax" message="The username is long"/>
                                <error type="onmin" message="The username is short"/>
                                <error type="onnull" message="This value is null"/>
                                <error type="onbadchars" message="The text must contain onlye alpha chars"/>
                        </errors>
                </form-element>
                <form-element name="password" type="text" maxlength="10" minlength="1" accepted-chars="alpha" allow-null="false" >
                        <errors>
                                <error type="onmax" message="The password is long"/>
                                <error type="onmin" message="The password is short"/>
                                <error type="onnull" message="The password is null"/>
                                <error type="onbadchars" message="The password must contain alpha chars"/>
                        </errors>
                </form-element>
                <form-element name="mail" type="mail" allow-null="false" >
                        <errors>
                                <error type="onnull" message="The e.mail is null"/>
                                <error type="oninvalidmail" message="You must type a valid e-mail"/>
                        </errors>
                </form-element>
        </form>
</simbelmyne>

The result is like:

<script language="javascript">
<!--
        //SCRIPT GENERATED BY Simbel JS Generator [ simbel-myne.blogspot.com ]

        function validateformulario(){
                var numericChars = "0123456789.";
                var alphaChars = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPKRSTUVWXYZ";
                var IsNumber=true;
                var IsAlpha=true;
                var Char;
                var _form_ = document.forms["formulario"];


                //Validating form element username

                if( _form_.username.value == "" ) {
                        alert(" No puede estar vacio ");
                        _form_.username.focus();
                        return false;
                }

                for (i = 0; i < _form_.username.value.length && IsAlpha == true; i++) {
                        Char = _form_.username.value.charAt(i);
                        if (alphaChars.indexOf(Char) == -1) {
                                alert(" El texto debe ser solo caracteres ");
                        _form_.username.focus();
                                return false;
                        }
                }

...

 

 

 
  Home | Download | Bugs | About me | Contact  

Copyright ©simbelmyne