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

Question

Question

Javascript: radio button text

asked on March 30, 2016

Hello,

I'm not sure if this is asked, but this is what I am trying to achieve...

I have a multi language form, on the basis of selection of language there are some Radio buttons in form which should change the label to the text in that language

Example.

Form has 2 languages & radio button to select language is: Language

German Text:

Radio button field name is: Arbeit bis

it has two options:

Anz. Arbeitstage

Enddatum bis

 

French Text:

Radio button field name is: Nombre jours ouvrables

two options.

ou

chéance le

 

I have tried to see the property of label by inspecting it, it shows the Field ID = 137

the two radio buttons are 137-0 & 137-1 

Can anyone please help?

Thanks in advance!

S

0 0

Answer

SELECTED ANSWER
replied on March 30, 2016 Show version history

Sahil,

Something like this should take care of what you're after.

$(document).ready(function () {
  $('[attr="Language"]').on('change', 'input', changeLanguage);

  function changeLanguage(event) {
    var language = event.target.value;
    switch(language) {
      case "English":
        $($('#q137 label')[1]).text("English Text 1");
        $($('#q137 label')[2]).text("English Text 2");
        $($('#q137 label')[3]).text("English Text 3");
        break;
      case "Français":
        $($('#q137 label')[1]).text("French Text 1");
        $($('#q137 label')[2]).text("French Text 2");
        $($('#q137 label')[3]).text("French Text 3");
        break;
      case "Deutsch":
        $($('#q137 label')[1]).text("German Text 1");
        $($('#q137 label')[2]).text("German Text 2");
        $($('#q137 label')[3]).text("German Text 3");
        break;
    }
  }
});
        

The case statements would need to match the values of your language field.

You can add or remove cases and the number of different radio button options as needed.

Edit: Corrected a grammar error.

0 0
replied on March 30, 2016

PERFECT!!!!

Thanks a lot!

0 0

Replies

replied on March 31, 2016

Hi John,

Is the same possible if I have a dropdown? I mean change options in dropdown...

Thanks in advance.

S

 

0 0
replied on April 1, 2016

Absolutely. The only thing you need to do is inside the case statement you would replace 'label' with 'option'.

For example:

        $($('#q137 option')[1]).text("English Text 1");

 

0 0
replied on April 1, 2016

Thanks John!

 

0 0
replied on March 31, 2016

Does anyone else have suggestion?

 

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

Sign in to reply to this post.