Skip to main content
Known Participant
April 5, 2023
Question

Validating dropdowns and textboxes before form will submit

  • April 5, 2023
  • 2 replies
  • 633 views

Hi,

 

i am struggling to come up with a solid code for checking that certain dropboxes/ text boxes have been filled in before the form will submit if the submit button is hit. i am also having issues with the code only doing something (changing the colour of a textbox) only after all dropdowns etc have been filled in.

 

This is the code i am currently using (emails etc have been removed)

 

var fld = this.getField("Today"); fld.value = util.printd("dd/mm/yyyy",new Date());
var field1 = this.getField("Text1");

if(this.getField("WSJ").value == "")

{

app.alert("Workshop Job must be filled in");

}

else if (this.getField("Bale Count").value == "")

{

app.alert("Bale Count must be filled in");

}

else


{

this.mailDoc({cTo: " ", cSubject: "Warranty Card" + (" ") + this.getField("WSJ").valueAsString, cMsg: " "})

}

field1.fillColor = color.green;
;

This topic has been closed for replies.

2 replies

Bernd Alheit
Community Expert
Community Expert
April 5, 2023

What happens when you use the script?

John CorfAuthor
Known Participant
April 5, 2023

Hi, 

 

I think i have found the issue with the script, I just the line field1.fillColor = color.green; the other side of the "}"

 

sorry for wasting peoples time!!

Legend
April 5, 2023

We see the code - but we don't see what you wanted to happen, and we don't see what happens instead.

I can see that whenever thsi code is run, field1 will be set to green whatever messages are issued, and whether or not an email is sent, perhaps you want that a line higher.

Symptoms/problems please. Also please check the console - any messages?

Also please tell us exactly how the code is triggered (eg calculate action for text field ABC; mouse up action for button; etc.).

John CorfAuthor
Known Participant
April 5, 2023

Hi, Thanks for the reply!

 

So I would like the form not to be submitted if either of the dropdowns are left empty. If both of the dropdowns have been filled in I would like the email to be sent and then after that have Text1 turn green. If neither of the drop downs are filled in I would like the errors to come up, the text box to stay its existing colour and the email not to be sent.

 

The code is triggered by the mouse up to run Java for a button

 

Hope that makes sense!

 

Thanks