2 Replies Latest reply on Jul 22, 2014 1:15 PM by MarcusS

    field validation before form submission

    MarcusS

      Upon clicking the "Submit" button on a form, I want to run a Javascript that first validates if all fields have been completed before copying and pasting user entries into an email. All seems to be working fine with the exception of one little error:

       

      The first field name after the getField command (in the script below "Writing 1") always gets priority over other fields, so when a user enters data in this field, all other fields are not being validated. Conversely, if this field remains empty the validation of all remaining fields is working fine. Here's the script:


      f = getField("Text1")||("Combo Box 171")||("Combo Box 9")||("Writing 1")

      if (f.value.length == 0)

          {

          app.alert("Please complete all required fields.")

          }

      else

      app.mailMsg({

      bUI: true,

      cTo: "marcus_saller@yahoo.co.uk",

      cSubject: "IWM Student Email",

      cMsg: "Dear Teacher," + "\n" +"\n" + "One of your students has completed a form on the Interactive Writing Manual with the following data:" + "\n" + "\n" +

      "Student name: " + this.getField("Text1").value + "\n" +

      "Level: "  + this.getField("Combo Box 9").value + " " + "\n" +

      "Essay topic: " + this.getField("Combo Box 171").value + " " + "\n" + "\n" + this.getField("Writing 1").value + " ",

      } );

       

      Many thanks