Change text of label based on radio button selection

I’m sorry if this has been asked already and I am sure it is a basic question, but I am new to the development side of Wix and was not able to find the answer in the forum. I am trying to change a text label based on the value selected of a radio button. I tried the below, but it did not work.

rdoIdeaType is the radio button which has 2 values.

txtIdeaTyperesult is the text label. It is hidden on page load and becomes visible once a selection is made on the radio button; that part works. Now I am trying to change the text of the label based on the selection of the radio button and that piece is not working.

What am I missing?

export function rdoIdeaType_change ( event ) { $w ( ‘#txtIdeaTypeResult’ ). show ();
if ( $w ( ‘#rdoIdeaType’ ). value === “Product” )
$w ( ‘#txtIdeaTypeResult’ ). text === “Product” ;
else
$w ( ‘#txtIdeaTypeResult’ ). text === “Service” ;
}

Hi! First, when setting the text of the txtIdeaTypeResult element, you are using the equality operator === instead of the assignment operator =. This means that you are not actually setting the text of the element, but rather checking if it is equal to the given string. Second, the if statement is missing curly braces {} around the code blocks that should be executed if the condition is true or false.

Try out:

export function rdoIdeaType_change(event) {
  $w('#txtIdeaTypeResult').show(); 
  if ($w('#rdoIdeaType').value === "Product") {
    $w('#txtIdeaTypeResult').text = "Product";
  } else {
    $w('#txtIdeaTypeResult').text = "Service";
  }
}

This is perfect, thank you! I misunderstood the === vs = and (I think) read a few articles wrong on the missing {}. Thanks again.