Sometimes you want to get selected value of radioButtonList using jQuery in your Yii powered application and it feels difficult due to Yii’s field naming conventions, as every field name contains array. Lets take an example. Suppose you have a radioButtonList as shown below and you want to enable/disable another field based on user selection from radioButtonList. We have added a JavaScript function onChange event of our radio buttons. Below code demonstrate how you can check selected value of radioButtonList using jQuery and perform conditional logic. <div class="row"> <?php echo $form->labelEx($model, 'nationality'); ?> <?php echo $form->radioButtonList($model, 'nationality', array( 'US' => 'US', 'Non US' => 'Non US', ), array( 'onChange'=>'toggleSSN();' )); ?> <?php echo $form->error($model, 'nationality'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'ssn'); ?> <?php echo $form->textField($model, 'ssn', array('size' => 9, 'maxlength' => 9, 'disabled'=>true)); ?> <?php echo $form->error($model, 'ssn'); ?> </div> function toggleSSN(){ var nationality = $('input[name="User[nationality]"]:checked').val(); if(nationality == 'US') { $('#User_ssn').attr('disabled', false); } else { $('#User_ssn').attr('disabled', true); } }
Get Selected Value from Yii RadioButtonList
Sometimes you want to get selected value of radioButtonList using jQuery in your Yii powered application and it feels difficult due to Yii’s field naming
Work with Scriptbaker
Let's talk about your project
Whether you're extending an existing platform, modernising legacy code, or planning something new, our engineers can help. Tell us what you're working on and we'll explore a practical technical solution together.
Related posts
JavaScript
jQuery Multi File Upload
Discover how jQuery File Upload simplifies file handling with multiple file selection, drag-and-drop support, upload progress bars, image previews, chunked uploads, and resumable transfers. This guide explores its key features, backend compatibility, common use cases, implementation considerations, and security best practices for modern web applications.
JavaScript
Toggle checkboxes with jQuery and Prototype JS
Learn how to toggle multiple checkboxes with jQuery, modern JavaScript, and Prototype.js. This updated guide covers Check All, Uncheck All, dynamic checkboxes, disabled fields, accessibility, common mistakes, and practical examples for building user-friendly forms and admin interfaces.
JavaScript
How to Add a jQuery Tooltip to Your Web Page
Learn how to add a jQuery tooltip to your web page using Tipsy. This guide explains how tooltips work, why they improve usability, how to implement and customize them, common use cases, and best practices for creating helpful and accessible web interfaces.