javascript - How can I show a div with jquery mobile when a radio button is selected? -


here jsfiddle relating question. http://jsfiddle.net/kane/mfjuv/

i've tried several things show/hide dropdown (div id: machinedropdown).

on load want machine dropdown hidden when user selects "machine" radio button needs show. can suggest solution me?

<div data-role="content" id="radio"     <form>       <fieldset data-role="controlgroup" data-type="horizontal" class="center-controlgroup">             <input name="radio-choice-h-6" id="radio-choice-h-6a" type="radio" checked="checked" value="on">             <label for="radio-choice-h-6a">run</label>             <input name="radio-choice-h-6" id="radio-choice-h-6b" type="radio" value="off">             <label for="radio-choice-h-6b">swim</label>              <!-- on select need hide "div id = "machinedropdown" -->             <input name="radio-choice-h-6" id="radio-choice-h-6c" type="radio" value="off">             <label for="radio-choice-h-6c">machine</label>          </fieldset> </form> </div>  <div data-role="content" id="machinedropdown"   <label class="select" for="select-choice-1">select, native menu</label>         <select name="select-choice-1" id="select-choice-1">         <option value="standard">machine 1</option>         <option value="rush">machine 2</option>         <option value="express">machine 3</option>         <option value="overnight">machine 4</option>   </select> </div> 

one way it, check whether radio both checked , element contains id specific machine.


firstly, set initial state of drop down hidden:

$('#machinedropdown').hide(); 

next, listen change event on radio inputs - if input both checked , has id specific machine input (radio-choice-h-6c) set drop-down display - otherwise, set hidden (so when change selected radio button machine option, drop-down isn't still showing):

$('input').change(function(){ // on change of radio buttons     if ($(this).is(':checked') && $(this).attr('id') == 'radio-choice-h-6c') {       $('#machinedropdown').show();       // if radio button checked , has machine id, show drop down.     }     else {       $('#machinedropdown').hide();       // else, re-hide it.     } }); 

jsfiddle here.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -