present :: Form.Element

present(element) -> boolean

 

Returns true if a text input has contents, false otherwise.

 

Example

 

<form id="present-example" class="example" action="#">

       <input type="text" name="username" id="username"/>

       <input type="text" name="email" id="email" size="30"/>

       

       <button type="submit">Send</button>

</form>

<div id="msg" class="notification"></div>

 

 

$('present-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

}

 


Prototype API 1.5.0 - prototypejs.org