Posts

Showing posts from February, 2016

Jquery code to check Radio Button on Text box focus

Here is sample code of jquery to select any radio button on text box focus. 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
$("#txtWidth").focusin(function () {
    $("#rbCustom").prop('checked', true);
});
</script>


<input type="radio" id="rbDefault" name="ResizeValue" value="DefaultSize" checked="checked" />Default<br />
<input type="radio" id="rbCustom" name="ResizeValue" value="CustomSize" />Custom  
<input id="txtWidth" type="text" />

Here txtWidth is a text box and rbCustom is a radio button. By default "rbDefault" radio button is checked. Using above script the "rbCustom" will get checked as soon as txtWidth text box is focused.