Simple client side validation using jQuery


// 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)
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...