General discussion

  • Creator
    Topic
  • #2317023

    Form validation in NN4 when form in DIV

    Locked

    by mr. origami ·

    I attach a Javascript form validator to my form and it works great – unless the form is in a DIV tag and I use Netscape 4 (Windows). It validates – I get alert boxes with the error message – but the form still submits!
    My page is simple:
    <.body>
    <.div id="Layer1" style="position:absolute; left:50px; top:53px; width:101px; height:46px; z-index:1">
    <.form action="otherpage.htm" method="post" name="form1" onSubmit="return validate();">
    <.input type="text" name="textfield">
    <.input type="submit" name="Submit" value="Submit">
    <./form>
    <./div>
    <./body>

    (NOTE: The “dots” were added above in the tags so my post does not contain HTML code. They do not appear in my actual page code!)

    See – nothing but a single form with a single textfield. Move the form out of the DIV tag – it works fine. Put form back in DIV tag – it doesn’t work (validates, but never “returns false” – it still submits)!

    How can I validate a form that’s inside a layer?!?!

All Comments

  • Author
    Replies
    • #3379280

      Reply To: Form validation in NN4 when form in DIV

      by kiddanger ·

      In reply to Form validation in NN4 when form in DIV

      If your statement “Netscape 4 (Windows)” implies NN4 and not ‘for’, then DIV is not supported. NN4 is not a standards compliant browser and thus Netscape has abandoned it to be more DOM (Document Object Model) compliant. NN4 uses layers.

      Testing with NN6+ or IE4+ should render your code correctly as long as your javascript function is called validate(), which IS case-sensitive.

      I would also remove the action=”otherpage.htm” and put it in your validate() routine:
      Ex.

      function validate() {
      var iname=”;
      iname = document.form1.textfield;
      if(!iname.value) {
      alert(‘Field cannot be blank’);
      iname.focus();
      return false;
      } else {
      document.form1.action=”otherpage.htm”;
      return true;
      }
      }

      This way your form will never be submitted unless it passes your validation tests.

Viewing 0 reply threads