Tutorials Point

  Learn Prototype
  Prototype Resources
  Selected Reading

Copyright © 2014 by tutorialspoint

  Home     References     Discussion Forums     About TP  

Prototype Form.Element present() Method

previous next AddThis Social Bookmark Button


This method returns true if a text input has contents, false otherwise.



Return Value :

  • It returns true if a text input has contents, false otherwise.


Try to submit the following form first without filling out the information, then again after typing some text in the fields:

<title>Prototype examples</title>
   <script type="text/javascript" 
function showResult()
  var valid, msg = $('msg')

  // are both fields present?
  valid = $('username').present() && $('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('Fill out all the fields.').style.color = 'red'
  return false


  <p>Click the button to see the result.</p>
  <br />

  <form id="example" action="#">
    <legend>User Details</legend>
    <p style="color:green;" id="msg">
	Fill out all the fields:
      <label for="username">Username</label>
      <input id="username" name="username" type="text">

      <label for="email">Email Address</label>
      <input id="email" name="email" type="text">
       <input value="result" type="button" onclick="showResult();>


To understand it in better way you can Try it yourself.

previous next Printer Friendly