// Put the following code in a client side javascript library var validationKey = "border" var validationValue = "1px solid #F2661D" var validationKeyDefault = "border" var validationValueDefault = "1px solid #ccc" function validateTimes(obj){ var ret = true var start = x$(obj.start) var end = x$(obj.end) var name = x$(obj.name) if(name.length){ if(name.val()==""){ name.css(validationKey,validationValue) alert("Name can not be empty") ret = false }else{ name.css(validationKeyDefault,validationValueDefault) } } return ret } // put this code in you submit button/link client event var flds = { "start":"#{id:start}", "end":"#{id:end}", "name":"#{id:name}" } if(validateTimes(flds)){ return true }else{ return false } or just do... validateTimes(flds)