· Apr 5, 2022

JQuery Question on Radio Buttons text

I have a few Radio buttons, some of which have to have the same value.  I need to know which one the user have selected, so I am using text, however it does not work well so far.

I have 4 Radio buttons: Apple, Pear, Lemon and Orange, with values: Apple, Pear have Value 1, and Lemon and Orange have Value of 2
(this unfortunatelly cannot be changed for this particular application)

I need to figure out that the user picked specifically Apple, so I am using text as follows:

var FruitSelected=$('[name='Nameoftheradiobuttonhere]:checked').parent().text();
alert (FruitSelected) - gives me proper text, which user selected - Apple.  When I pick other fruits - it also gives me proper text for the corresponding fruit.

However, when I run a simple 

if (FruitSelected)='Apple' { Do something} - it is always true, regardless of what I picked.
When I use if (FruitSelected)==='Apple' - it is always false, regardless of what I pick.

Please advise and sorry if this is a simple question.

Product version: IRIS 2022.1
Discussion (5)2
Log in or sign up to continue