9 Replies Latest reply on Apr 22, 2009 10:23 AM by slang75

    User fills in textbox 1 prompted to complete textbox 2...how?

      Hi guys,


      Sorry for the 2nd post but I am getting desperate here.


      I have a simple form with text fields, and only two of the fields, if one is filled I would like the user prompted to complete the other field next to it, and vice versa. If neither is filled no problem.


      Like this,


      If a user fills in textbox 1 prompted to complete textbox 2

      If a user fills in textbox 2 prompted to fill textbox 1


      Does anyone know how to do this? I do not have a submit button on the form, but would still like the guide the use through complete what I need from them.


      This was the only code I could find but am not sure how I would use this in my for and 2 text feilds.


      <form name = "myform" onsubmit = "return checkIt()">
      <p>Textbox 1 <input type = "text" name = "textbox1" size = "25"></p>
      <p>Textbox 2 <input type = "text" name = "textbox2" size = "25"></p>
      <input type = "submit" name = "submitButton" value = "Submit the form">

      <script type = "text/javascript">

      function checkIt() {
      var t1 = document.myform.textbox1.value;
      t1 = t1.replace(/^\s+/,"") // delete leading spaces
      var t2 = document.myform.textbox2.value;
      t2 = t2.replace(/^\s+/,"") // delete leading spaces

      if (t1.length > 0 && t2.length == 0 ) {
      alert ("You must fill in Textbox2 as well as Textbox1 ");
      return false;

      if (t1.length == 0 && t2.length > 0 ) {
      alert ("You must complete Textbox1 if you have filled in Textbox2 ");
      return false;

      return true; // both fields could be blank





      Can anyone help?