scripts to check variable is empty or not
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 07:39 PM
I have create 2 variable as per below
variable A = multiline text
variable B - attachment
the above variable is not set as mandatory field and I would like to create a on submit scripts to check base on the below scenario
Scenario 1
Variable A = empty
Variable B = empty meaning no attachment
the script should alert with message when requester press order now button
Scenario 2
Variable A = not empty
Variable B = empty meaning no attachment
the script is not alert with message and requester can press order now button
Scenario 3
Variable A = empty
Variable B = not empty meaning got attachment inside
the script is not alert with message and requester can press order now button
thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 08:48 PM
Hi @TMKAM ,
You can create onSubmit client script with script as below:
function onSubmit() {
var itemA = g_form.getValue('variable_a');
var itemB = g_form.getValue('variable_b');
if (!itemA && !itemB) {
g_form.addErrorMessage('Please fill out both variables');
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 09:17 PM
@Community Alums
Thank you for the scripts and it did check the both variable but when I attach files in variable B it still prompt the error messages that I cant press order now.
thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 09:21 PM
Hi there,
The script above only prevent submitting when both are empty. Can I have the screenshot of your script? and also is there any other onSubmit client script run along with it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 10:26 PM
Hi TMKAM,
Please try below script it works,
Please mark my answer correct if it works for you!!