cancel
Showing results for 
Search instead for 
Did you mean: 

Clear out text field based on value list options

JhansiV
Contributor III

There are two fields as below:

1. Please choose Yes/No,

2. If Yes, please specify, (text box)

 

If i chose "Yes" for 1, 2 gets displayed. 

 

I want to clear out text box 2 if Yes is changed to No for 1.

39 REPLIES 39

DavidPetty
Archer Employee
Archer Employee

Jhansi, you could do it either via a data feed, scheduled bulk update or custom object.

 Advisory Consultant - Archer, an RSA Business

Can you please help me with custom object?

Hi Jhansi -- What is the display control on the values list (drop down, radio buttons)? And is the text field a regular text field or a text area?

Hi Taylor,

What is the display control on the values list (drop down, radio buttons)? - IT is a drop down 

And is the text field a regular text field or a text area? - regular text field.

GeoffTaylor2
Contributor III

Try this. It works for me in 6.4 SP1.

 

<script>
const yesNoFieldId = 21554; // Replace with the field ID of the Yes/No field
const textFieldId = 21552; // Replace with the field ID of the text field
const yes = 73754; // Replace with the ID of the 'Yes' value in the Yes/No field
const no = 73755; // Replace with the ID of the 'No' value in the Yes/No field

function setTextField(fld,val) {
var textFieldAttributes = new Array();

textFieldAttributes.push({
enabled: true,
emptyMessage: '',
validationText: val,
valueAsString: val,
lastSetTextBoxValue: val});

var textFieldAttributesSerialised = Sys.Serialization.JavaScriptSerializer.serialize(textFieldAttributes[0]);

$('input[id$="'+ fld +'c"]').val(val);
$('input[id$="'+ fld +'c_ClientState"]').val(textFieldAttributesSerialised);
}

Sys.Application.add_load(function() {
const yesNoClientId = $CM.getFieldById(yesNoFieldId).clientId;

$('div[id^="' + yesNoClientId + '"]').change(function() {
const yesOrNo = $CM.getFieldValue(yesNoFieldId);

if (yesOrNo !== null && yesOrNo[0] === no + ':0') {
setTextField(textFieldId, '');
}
});
});
</script>

Nice work Geoff

 

Word of caution, use the following function to set/clear a text field.

function setTextField(fld,val) {
var textFieldAttributes = new Array();

textFieldAttributes.push({
enabled: true,
emptyMessage: '',
validationText: val,
valueAsString: val,
lastSetTextBoxValue: val});

var textFieldAttributesSerialised = Sys.Serialization.JavaScriptSerializer.serialize(textFieldAttributes[0]);

$('input[id$="'+ fld +'c"]').val(val);
$('input[id$="'+ fld +'c_ClientState"]').val(textFieldAttributesSerialised);
}

 Advisory Consultant - Archer, an RSA Business

Thanks David! I had a feeling I wasn't doing that exactly the right way.

I updated my code with your function.

Hey David, somehow it is not working for me. can you please assist me some more details.

Hi Saumya  

 

A few questions:

  • Is there any errors being reported in the developer tools console?
  • Is the text field on a tab not currently being displayed?
  • Is the text field on the layout?
  • Is the text field private?

 Advisory Consultant - Archer, an RSA Business