3

Hi I am attempting to do some Jquery form logic, dependent upon which value is selected from a previously selected radio button, or upon change to it...the following in essence would happen.

 if(selectedRadioButton == '2mL')
  {

    // do some logic here

This is how I have declared my radio form with two options in my view...

<div class="row">
    <?php echo $form->labelEx($model, 'oneml_twoml'); ?>

        <div class="compactRadioGroup">
        <?php
            echo $form->radioButtonList($model, 'oneml_twoml',
                array(  '1mL' => '1mL',
                        '2mL' => '2mL'
                         ) );
        ?>

        </div>
        <?php echo $form->error($model, 'oneml_twoml'); ?>
</div>

Using Jquery, how can I extract the selected value from my radio button options to use for doing logic?

  • 1
    Have you read jQuery documentation on selecting? If you do a web search you will find many examples of how to get the value of a radio button. such as here http://stackoverflow.com/questions/3464075/get-value-of-radio-button-group – Elliott Aug 07 '12 at 14:11
  • thanks, I had searched myself but could not figure out how to do this in the context of a yii form. However, I just figured out do to this specific link. –  Aug 07 '12 at 15:23

1 Answers1

4

Figured out how to do this...

var one_two_ml = $('input:radio[name=ModelName[oneml_twoml]]:checked').val();

And subsequently

 if (one_two_ml == '2mL')
  {
    var net_output = some_variable + 5;  

   $('#ModelName_net_output').val(net_output); 
  }