Copy a Radio Group's selected button's label to a text element while typing.

  • LNorth
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 6
  • Thank you received: 0

LNorth created the topic: Copy a Radio Group's selected button's label to a text element while typing.

I am using the function:

var tmp = JQuery("[name=\"ff_nm_SELECTLISTNAME[]\"] option:selected").text();

to get the Title, (displayed text), of the selected item of a Select From List element to automatically enter into the Value field of a Textfield element.

I also want to perform the same function on a Radio Group to enter the Title of the selected button into the Value field of another Textfield element. The option:selected part of the function is unable to see the Title as the selected button needs to be identified first.

What script do I need to access and get the selected button Title?
#236764
  • mihaela
  • Away
  • Administrator
  • Administrator
  • Posts: 2571
  • Karma: 87
  • Thank you received: 344

mihaela replied the topic: Copy a Radio Group's selected button's label to a text element while typing.

Hello,

The selected buttons in radio group can be targeted by using:
JQuery('[name="ff_nm_radiogroupname[]"]:checked')
instead of by using "option:selected".

The value selected can be targeted by using:
JQuery('[name="ff_nm_radiogroupname[]"]:checked').val()

As for the title it depends on which theme you are using, BreezingForms or Bootstrap. Either way, you can try to write the code to fetch the text based on the above code.

Let me know whether you have managed to do so.

Regards,

Mihaela
#236821
The following user(s) said Thank You: LNorth
  • LNorth
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 6
  • Thank you received: 0

LNorth replied the topic: Copy a Radio Group's selected button's label to a text element while typing.

Hi Mihaela.
I have not been able to get either version to work. I am entering the code in the Form Entry function of a radio group with the name button to load the result into the value field of a textfield with the name button_copy.

using the script:
ff_getElementByName("button_copy").value=JQuery('[name="ff_nm_button[]"]:checked');
or
ff_getElementByName("button_copy").value=JQuery('[name="ff_nm_button[]"]:checked').val();
I get the result [object Object] in both cases.

the script below does give the result but it is inelegant, too long and inflexible, i.e. it has to be recoded if I change anything in the radio group's List.

function ff_button_init(element, condition)
{
switch (condition) {
case 'pageentry':
vals =ff_getElementByName('button').value=element.value;
break;
default:;
} // switch
if (vals==1){
ff_getElementByName("button_copy").value="Yes";
}//if
else if (vals==2){
ff_getElementByName("button_copy").value="Maybe";
}//else if
else {
ff_getElementByName("button_copy").value="No";
}//else
} // ff_button_init

Thank you for your help,

Lawrence.
#236847
  • mihaela
  • Away
  • Administrator
  • Administrator
  • Posts: 2571
  • Karma: 87
  • Thank you received: 344

mihaela replied the topic: Copy a Radio Group's selected button's label to a text element while typing.

Hello,

I've tested again this code you've sent:
ff_getElementByName("button_copy").value=JQuery('[name="ff_nm_button[]"]:checked').val();
and the "button_copy" textfield was properly filled in with the options value.

If you are using BreezingForms theme, you should be able to get the title of selected option like this:
ff_getElementByName("button_copy").value=JQuery('[name="ff_nm_button[]"]:checked').next().text();
This will be equivalent for:
var tmp = JQuery("[name=\"ff_nm_SELECTLISTNAME[]\"] option:selected").text();

Other solution, which requires some coding and making changes if radio group definition is changed is the following:
function ff_button_init(element, condition)
{
var val =JQuery('[name="ff_nm_button[]"]:checked').val();

if (val=="value1"){
ff_getElementByName("button_copy").value="Yes";
}//if
else if (val=="value2"){
ff_getElementByName("button_copy").value="Maybe";
}//else if
else if (val=="value3"){
ff_getElementByName("button_copy").value="No";
}//else if

} // ff_button_init
NOTE: You have to replace "value1", "value2" and "value3" with the real radio group option's values. This code will have to be changed in case you add an additional option to the group.

Also, instead of putting this code in the Initialization script it would be more logical if you put this in the radio group's Actionscript, but it should work this way as well.

Let me know whether this works for you.

Regards,

Mihaela
#236858
  • LNorth
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 6
  • Thank you received: 0

LNorth replied the topic: Copy a Radio Group's selected button's label to a text element while typing.

Thank you.
Both the text and the value options now work with the BreezingForms theme. Is there any way it can be done with bootstrap?
#236979
Moderators: ForumSupporttomeperica
Time to create page: 0.069 seconds

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Summer Sale!

50% discount on all of our extension subscription plans, templates and icon packs!

Get Your Subscription Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99 for just 49! (Summer Sale)

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here