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

Question

Question

How do I use Javascript to set a radio button in Forms?

asked on January 24, 2014

I want to take a field that will be hidden by CSS and filled during a Lookup, and use that value to determine what option in a radio field should be automatically selected. 

 

I cannot seem to reference it properly, does anyone have any advice or can help with this problem?

 

0 0

Answer

SELECTED ANSWER
replied on January 24, 2014 Show version history

This should get you started. This code uses a radio button field (with the radio css class) and a single line field (with the filledField css class)

 

$(document).ready(function () {
  
  $('.filledField input').blur(function () {
    var value = $(this).val();
    $('.radio').find($('input[value="' + value + '"]')).attr('checked', true);
  });
});

Currently the code runs when the user leaves the single line field.

1 0

Replies

replied on January 24, 2014 Show version history

$('#id:radio') - Insert the ID of the radio button in place of 'id'. Not sure if that's what you're looking for.

 

These jQuery API examples may help with what you need: http://api.jquery.com/val/

1 0
replied on January 24, 2014

so if i need to select field 1, it's ID is q1, should i say it's '#q1' or 'q1'?

replied on January 24, 2014 Show version history

But I still cannot set the value. I have confirmed though that I can get the value using the .val() function, but putting a variable inside of those parenthesis is not working. It will apparently change the value but not the visual representation of the radio button.

 

EDIT: I noticed that because I have set the options to have values, which is the actual information I was being returned and not the boolean value of whether or not it is selected. 

0 0
replied on January 24, 2014

Have you tried something like:

$( "input").val([ "radio1value" ]);

 

That should set and show the visual representation for the radio button.

1 0
replied on January 24, 2014

Seriously having no luck.

 

How am i supposed to modify your sample code to target a specific input field and not just all of them. Maybe I am doing that wrong

0 0
replied on January 24, 2014

So, you're populating a hidden field (what type of field) with a value (one or more) and then you want to select the radio button that matches that value? Or you want to replace the radio button options with the values from the field?

0 0
replied on January 24, 2014 Show version history

Maybe I gave too much information at first and now it's confusing.

 

Say I have a field, it says Yes. That is also the value of the radio button I want selected. How do I take that field value of "Yes" and set the "Yes" option in a "yes" or "no" radio button options

 

0 0
SELECTED ANSWER
replied on January 24, 2014 Show version history

This should get you started. This code uses a radio button field (with the radio css class) and a single line field (with the filledField css class)

 

$(document).ready(function () {
  
  $('.filledField input').blur(function () {
    var value = $(this).val();
    $('.radio').find($('input[value="' + value + '"]')).attr('checked', true);
  });
});

Currently the code runs when the user leaves the single line field.

1 0
replied on January 24, 2014 Show version history
var radiovalue=$('#q1').val(); // gets value sets it to a variable named radiovalue


$('input').val(yes); //sets value of the input box to the radio button

#q1 would be the id of the text field

I think that should work.

2 0
replied on January 24, 2014

I will be sure to give this a try soon. Thanks for the help

0 0
replied on January 27, 2014

Thanks for your help, this is going to make my form very nice

0 0
replied on November 15, 2014

anyone know how I might easily change the code to work for a multi-line table? I am hoping to mark off a table automatically when possible from a lookup result. I already have the code working for the rest of the table, but using a radio button for one of the columns would be nice.

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

Sign in to reply to this post.