Client Script detect if value of field is --None--
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2019 12:42 PM
I have a client script where if Field A is yes, I want Field B to change its value and if Field A is no or the default --None-- then I want Field B to change back to its original state. I can't get the script to detect if Field A is --None--. It works fine if Field A is Yes or No. I have tried just doing a blanket "else" statement and detecting if(Field A == '') but neither of those work.
My script is:
if(g_form.getValue('Field A' == 'yes'){
g_form.setValue('Field B', 'yes')
}
else{
g_form.setValue('Field B', 'no')
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2019 12:47 PM
Is "None" a custom choice value you have added to your field or you are using default Choice Specification as "Dropdown with None".
If it is the latter one your script should work fine.
if(g_form.getValue('category') == '')
{
alert(g_form.getValue('category'));
}
If you have added an custom choice test the below code:
if(g_form.getValue('category') =='none')
{
.......
}
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2019 12:49 PM
I am using the "Dropdown with None" method, but that script doesn't work. Checking if the value of the field is '' isn't changing the second field.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2019 01:00 PM
can you add alert() statement in your client script to verify value of field when none is selected?
This will help to troubleshoot further.
The option of "--None--" has a value of ""
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2019 03:58 AM
i created fielda as a choice field with None with values yes and no.
1) if i put an on change client script on field a, the script does NOT register when newValue == ''.
2) if put the code below on an on submit client script it works
BUT you would then NOT have access to fieldb previous value.
function onSubmit() {
alert('field a is ' + g_form.getValue('u_fielda'));
if (g_form.getValue('u_fielda') == 'yes'){
alert('1');
}
else if (g_form.getValue('u_fielda') == 'no' ){
alert('2');
}
else if (g_form.getValue('u_fielda') == ''){
alert('3');
}