Java hell-p?

Out of context: Reply #3

  • Started
  • Last post
  • 3 Responses
  • vaxorcist0

    try this, worked for me... change in validate_form function

    ... in the head....

    <script type="text/javascript">
    //------------------------------...
    function validate_email(field,alerttxt)
    {
    with (field)
    {
    apos=value.indexOf("@");
    dotpos=value.lastIndexOf(".");
    if (apos<1||dotpos-apos<2)
    {alert(alerttxt);return false;}
    else {return true;}
    }
    }
    //------------------------------...
    function validate_form(thisform)
    {
    with(thisform)
    {
    if (validate_email(email,"Not a valid e-mail address!")==false)
    {thisform.email.focus();return false;}
    if (validate_required(name,"fill in the name")==false)
    {thisform.name.focus();return false;}
    }
    }
    //------------------------------...--
    function validate_required(field,alerttxt)
    {
    with(field)
    {
    if (value==null||value=="")
    {
    alert(alerttxt);return false;
    }
    else
    {
    return true;
    }
    }
    }

    </script>

    ....... and in the HTML:

    <form method="post" name="myform" action="#" onsubmit="validate_form(this); return false">
    <p>email:
    <input type="text" id="email" name="email" /></p>
    <p>name:
    <input type="text" id="name" name="name" /></p>
    <p>
    <input type="submit" name="submit">
    </form>

View thread