TOPIC:

Copy a Radio Group's selected button's label to a text element while typing. 1 year 2 weeks ago #236764

  • Topic Author
  • LNorth
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 6
  • Thanks: 0
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?

Please Log in or Create an account to join the conversation.

Copy a Radio Group's selected button's label to a text element while typing. 1 year 1 week ago #236821

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 413
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
The following user(s) said Thank You: LNorth

Please Log in or Create an account to join the conversation.

Copy a Radio Group's selected button's label to a text element while typing. 1 year 1 week ago #236847

  • Topic Author
  • LNorth
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 6
  • Thanks: 0
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.

Please Log in or Create an account to join the conversation.

Copy a Radio Group's selected button's label to a text element while typing. 1 year 1 week ago #236858

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 413
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

Please Log in or Create an account to join the conversation.

Copy a Radio Group's selected button's label to a text element while typing. 1 year 13 hours ago #236979

  • Topic Author
  • LNorth
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 6
  • Thanks: 0
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?

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Moderators: ForumSupport
Time to create page: 0.050 seconds

Summer Sale!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

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!