0

Hi all how could I insert a (if) statement to this code that if (element1) value is not blank then (element2) is required before submitting.

I'm already using a list of validated element that needs to be filled before subtitling

I would like to add a few more to that list depending on if some element are not empty.

Here's part of the code I'm not sure how or where to inset the if statement.

function submitBotton() {

  var tool1 = document.getElementById("OtherEquipment1").value

  if (tool1 !== '') {
    toolowner1: "Equipment Owner is required!",
  }

  var toValidate = {
    prefDate: "Date is required!",
    Person: "Name is required!",
    Loc: "Location is required!",
    Time: "Time is required!",


  };

  var idKeys = Object.keys(toValidate);

  var allValid = true;
  idKeys.forEach(function(id) {
    var isValid = checkIfValid(id, toValidate[id]);
    if (!isValid) {
      allValid = false;
    }
  });

  if (allValid) {
    addRecord();
  }
}

Thanks

Yvan L
  • 233
  • 3
  • 12
  • Hey Yvan. Could you add some interpunction to your question? It's barely readable at the moment. – Emiel Zuurbier Feb 08 '20 at 18:33
  • Please identify which variables represent element#1 and element#2. – Tedinoz Feb 09 '20 at 12:10
  • "_if (element1) value is not blank_". Are you familiar with the method `isBlank()` [doc](https://developers.google.com/apps-script/reference/spreadsheet/range#isblank) – Tedinoz Feb 09 '20 at 12:13
  • Im probably not asking the proper question what im triyng to get at is that if tool1 is not blank then add toolowner1: "Equipment Owner is required!" to the variable toValidate: so instead of having 4 item in my toValidate list it now as 5 hope this make sense – Yvan L Feb 09 '20 at 16:49
  • I am not quite sure how your question is related to Google Sheets. It looks like `tool1` is a structure element of your HTML page rather than contents from Google Sheets. Please try to rephrase your quesiton and give more context and explanation about what you are doing – ziganotschka Feb 10 '20 at 11:02

0 Answers0