present
present(element) -> boolean
Returns true if a text input has contents, false otherwise.
Example
This method is very handy in a generic form validation routine. Try to submit the following form first without filling out the information, then again after typing some text in the fields:
Here is the complete JavaScript code for the above example:
$('example').onsubmit = function(){
var valid, msg = $('msg')
// are both fields present?
valid = $(this.username).present() $(this.email).present()
if (valid) {
// in real world we would return true here to allow the form to be submitted
// return true
msg.update('Passed validation!').style.color = 'green'
} else {
msg.update('Please fill out all the fields.').style.color = 'red'
}
return false
}