Validate your HTML form using Javascript

You can validate your HTML form simply applying this static class…
example:

<form
onsubmit="

return
Validate.form(this,
                     {notEmpty:
                                   ['userEmail','reEmail', 'userPassword','rePassword'],
                    equalTo:
                                  ['userPassword,rePassword','userEmail,reEmail'],
                   update:
                                'top-message'})
">...<form>

Here is validation code…

var Validate={

	// set notEmpty as parameter to perform not empty validation
	// set equalTo as parameter to compare 2 fileds validation...
	// you have to setup update parameter so... it will setup the error message
	form: function(form, params) {

		var msg="";

		// validate "notEmpty"
		for(var i=0;  i < params .notEmpty.length; i++) {
			var field=params.notEmpty[i];
			if(this.isEmpty(this.getField(form, field))) {
				msg +="
  • "+field+" is emptyrn"; this.errorHighlight(field); } else { this.removeHighlight(field); } } // validate "equalTo" for(var i=0; i<params .equalTo.length; i++) { var fields=params.equalTo[i]; var field1 = fields.substring(0,fields.indexOf(",")); var field2 = fields.substring(fields.indexOf(",")+1,fields.length); if(this.getField(form, field1).value !=this.getField(form, field2).value) { this.errorHighlight(field1); this.errorHighlight(field2); msg +="
  • "+field1+" does not equal to "+field2+""; } } // set message if(msg !="") { document.getElementById(params.update).innerHTML="
      "+msg+"
    "; document.getElementById(params.update).style.textAlign="left"; // show effect EasyAjaxEffectMapping.showEffect(params.update); return false; } return true; }, isEmpty: function(field) { if(field.value !=null && field.value.length>0) return false; else return true; }, removeHighlight: function(field) { var fObj=document.getElementsByName(field).item(0); if(fObj !=null) { fObj.style.border="1px"; fObj.style.borderColor="#0066cc"; fObj.style.borderStyle="solid"; } }, errorHighlight: function(field) { var fObj=document.getElementsByName(field).item(0); if(fObj !=null) { fObj.style.border="5px"; fObj.style.borderColor="red"; fObj.style.borderStyle="solid"; } }, getField: function(form, fieldName) { var rootDoc=form.getElementsByTagName("input"); for(var i=0; i< rootdoc .length; i++) { if(rootDoc.item(i).name==fieldName) { return rootDoc.item(i); } } } };
  • Thank you think it will helpful…

    How I minimized lots of code from my DAO implementation

    I am working on a project where I have 10 domain models my main purpose is to implement CRUD(Cut Retrieve/Read Update Delete) for each model…

    And I don’t have much time to demonstrate it’s first iteration… I was thinking how I can reduce my development time… rather implementing 10 separate DAO for each model…

    At last I made a common DAO interface..

    It uses this code snap:


    public interface CommonDAO{

    public Integer create(Object o);

    public Object update(Object o);

    public List retrieve(Object… p);
    public Object retrieve(Integer id, Class cls);

    public boolean delete(Object o);
    public boolean delete(Collection c);
    public boolean delete(Integer id, Class cls);

    }

    And implemented:



    ……………..
    public List retrieve(Object... p) {

    List list=new Vector();

    if(logger.isDebugEnabled())
    logger.debug(“Entered: retrieve (String)”);

    try {
    switch(p.length) {
    case 0:
    break;
    case 1:
    list=getHibernateTemplate().find((String)p[0]);
    break;
    case 2:
    list=getHibernateTemplate().find((String)p[0], (Object[])p[1]);
    break;
    }

    }
    catch(Exception e) {
    logger.error(e);
    }

    return list;
    }

    public Object retrieve(Integer id, Class cls) {
    Object o=null;

    if(logger.isDebugEnabled())
    logger.debug(“Entered: retrieve(Integer, Class) “);

    try {
    o=getHibernateTemplate().get(cls,id);
    }
    catch(Exception e) {
    logger.error(e);
    }

    return o;
    }
    …………….

    And now feeling quite happy … because it saved my lots of code…

    Thank you.

    Failed to load or instantiate TagExtraInfo class

    If u face this problem…

    Just remove jsp-api.jar from your WEB-INF/lib directory

    EasyAjax: Java Tag library

    U dont need to know Javascript ….
    just browser and chkou the example application

    EasyAjax Website

    My replica…

    Hi
    i am thinking about my class project….

    though primarily i have decided that i will develop a virtual my replica…

    !? Interesting?

    In project based work area.. i always faced several problems … because of my extensive project pressure… and also i am forget minded ppl…. :D

    I think if i can develop a system which will never forget anything… basically that system will clone of my brain… and it will gradually increase it’s knowledge … (through my peer’s brain also from me…)

    Think u working in your company… your peers also working…. they are also using this virtual software which simulating their own brains…

    You got new message (email chat etc.. whatever or new task)
    it will measure your current workload it will chkout your computer input device’s response time… network bandwidth etc… and it will reach a near decision if it give any wrong result it will memorize this new decision……

    This kind of… though its is rough thinking…. but as i am Java developer… so i will implement this platform using Java…. and JNI… and Java EE for project manager control….

    Lemme know about your thinking….

    Thank you
    NHM Tanveer Hossain Khan (Hasan)
    http://hasan.we4tech.com [ajax template]

    http://www.somewherein.net

    http://www.somewherein.net/blog

    upload_max_filesize related problem

    I have heard and faced this problem several times when i need to upload more than 2M file using my php script….

    -> “upload_max_filesize” is one php.ini defined property… this propery limits the maximum uploadable content size…

    – PHP manual described this propery as “PHP_INI_PERDIR”…

    – PHP_INI_PREDIR means “Entry can be set in php.ini, .htaccess or httpd.conf “…

    -

    - You need to upload more than 2M file

    ->> You can do it just change php.ini “upload_max_filesize” propery …
    – Example: upload_max_filesize=100M

    -

    - When you dont have php.ini access….

    ->> You can change this property using .htaccess file…

    (#)File: .htaccess
    ————————————————–
    php_value upload_max_filesize 100m
    ————————————————–

    *NOTE: (—-) this signed used for indicating start and end of file…

    Save in your php web root directory…

    Thats it…

    Thank you

    NHM Tanveer Hossain KHan (h asan)
    http://hasan.we4tech.com [Ajax based WP template]

    http://www.somewherein.net

    http://www.somewherein.net/blog

    my tweets

    • @ReDrUmNZ after increasing buffer to 2 mins it's all gone. 1 week ago
    • @ReDrUmNZ i had a video wall kinda thing where around 6 small live streams were auto playing, due to 0 buffer it was leaking sound "hizzsss" 1 week ago
    • @ReDrUmNZ fyi, hi i got that video hissing things solved. it was due to buffer :) 1 week ago
    • lesson learned #Android #html5 #VIDEO doesn't work if you have none supported source 1 month ago
    • @ReDrUmNZ hi i'm using several VideoDisplay and a big VideoPlayer for showing whenever those are dbl clicked. do u think it has reltn too ? 1 month ago

     

    January 2006
    S S M T W T F
    « Dec   Feb »
     123456
    78910111213
    14151617181920
    21222324252627
    28293031  

    Flickr Photos

    Beauty Lassi and Faluda - http://www.khadok.com/t/restaurants/beauty-lassi-and-faluda-old-dhaka/65?l=en

    Beauty Lassi and Faluda - http://www.khadok.com/t/restaurants/beauty-lassi-and-faluda-old-dhaka/65?l=en

    Khazana http://www.khadok.com/t/restaurants/khazana-a-treasure-of-indian-cuisine/249?l=en

    Khazana http://www.khadok.com/t/restaurants/khazana-a-treasure-of-indian-cuisine/249?l=en

    Khazana http://www.khadok.com/t/restaurants/khazana-a-treasure-of-indian-cuisine/249?l=en

    More Photos
    Follow

    Get every new post delivered to your Inbox.