You are viewing limited content. For full access, please sign in.

Question

Question

Hide or show a field based on radio button value

asked on September 17, 2018

I am populating the radio buttons based on a look up rule. 
So first I write the value from the database to  a hidden field - q2 and using Javascript I populate the radio button - #Field5 value.
Now if the radio button value is '2' it should display a multiline field - #Field10.
Field Rules are not working here. So I am using the Javascript. The code works till where it is writing to the multiline field with the value. But it doesn't show or hide the field. Am I supposed to have a click event?

//Populate Radio Buttons based on Hidden field value
    $('#q2 input').change( function() {
      
         $("#Field5").find($('input[value="' + $('#q2 input').val() + '"]')).attr("checked", true);
     
      if ($('#q2 input').val() == "2") {
        $("#Field10").val("2");

        $('#q10').show();

    } else {

      $('#q10').hide(); 

    }
       
    });

0 0

Answer

SELECTED ANSWER
replied on September 17, 2018

Example from Laserfiche for Radio Button

Targets selected radio buttons or checkboxes that have an id starting with Field14.

$("input[id^='Field14']:checked")

$('input[id^="Field14"]:checked').val()

 

Couple things you may want to check into

I think you need to add a Selector
In choosing the Field Number, In other examples I've seen " " not ' ' unless they were using a CSS Class. Examples below

$("#q10 input").trigger('change');

$('.ShowInvRec input').trigger('change');

1 0

Replies

replied on September 17, 2018 Show version history

Hi Bina

I have found that when using JS to make changes to fields, I have to trigger the field for things likes Field Rules or Lookups to recognize the change.

ie: ('#q10').trigger.change

 

My syntax suffers from lack of coding experience but this should get you moving in the right direction.

0 0
replied on September 17, 2018

Tried the following but none of these works

('#q10').trigger.change

$('#q10').trigger("change");

$('#q10').trigger("onchange");

0 0
SELECTED ANSWER
replied on September 17, 2018

Example from Laserfiche for Radio Button

Targets selected radio buttons or checkboxes that have an id starting with Field14.

$("input[id^='Field14']:checked")

$('input[id^="Field14"]:checked').val()

 

Couple things you may want to check into

I think you need to add a Selector
In choosing the Field Number, In other examples I've seen " " not ' ' unless they were using a CSS Class. Examples below

$("#q10 input").trigger('change');

$('.ShowInvRec input').trigger('change');

1 0
replied on September 17, 2018

The following format you suggested worked!

$('.ShowInvRec input').trigger('change');

Thanks a lot!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.