Hide fields based on condition in a form
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Requirement: When contact has value display contact and hide: u_name, u_phone, u_company and u_email else vise versa
function onLoad() {
var contact = g_form.getValue('contact');
if (contact) {
// Contact has value → show contact, hide other fields
g_form.setDisplay('contact', true);
g_form.setDisplay('u_name', false);
g_form.setDisplay('u_phone', false);
g_form.setDisplay('u_company', false);
g_form.setDisplay('u_email', false);
} else {
// No contact → hide contact, show other fields
g_form.setDisplay('contact', false);
g_form.setDisplay('u_name', true);
g_form.setDisplay('u_phone', true);
g_form.setDisplay('u_company', true);
g_form.setDisplay('u_email', true);
}
}
When the contact has value it hides the rest of the fields. But when the contact does not have value, it shows other fields and the also the contact field.
Why?
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago - last edited 2 hours ago
As you have done in Client script, Try this:
Select field as Contact
function onChange(control, oldValue, newValue, isLoading) { if (isLoading) { return; } if (newValue != '') { g_form.setDisplay('contact', true); g_form.setDisplay('u_name', false); g_form.setDisplay('iphone', false); g_form.setDisplay('company', false); g_form.setDisplay('u_email', false); } else { g_form.setDisplay('contact', false); g_form.setDisplay('u_name', true); g_form.setDisplay('iphone', true); g_form.setDisplay('company', true); g_form.setDisplay('u_email', true); } }