View Single Post
Old 01-02-2013, 11:35 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Well, from another standpoint, that code is needlessly complicated.

Why not simply pass this into the function doing the check?

Or do it the more modern unobtrusive way, in the first place:

Code:
<!DOCTYPE html>
<html>
<body>
<form id="example"><!-- named forms are obsolete...use id instead -->
<input type="text" size="20" name="email">
<strong>Feedback please:</strong>
<textarea name="S1" rows="2" cols="20"></textarea>
<input type="submit" name="B1" value="Submit">
</form>

<script type="text/javascript">
(
  function( )
  {
      var form = document.getElementById("example");
      form.email.onchange = 
          function( )
          {
              if ( this.value.indexOf("@") < 0 )
              {
                  alert("invalid email address");
                  this.focus();
              }
         }
  }
)();
</script>
</body>
</html>
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote