javascript - How to retrieve values in select tag within the radio button using jquery? -


i have following html radio tags. basiclly, has 3 radio button , user can pick 1 , want jquery code pick value checked radio.

there 3 radio button, 1 day, 1 n/a , 1 time. , once user click time, can selected time between 12:00 20:00 in tag.

i know using .val() extract value other 2 options, figuring out how extract values on times when time radio button selected.

i using meteor framework project, guess jquery question.

html

<tr>     <td>monday</td>     <td><input type="radio" name="mon" value="all">all day</td>     <td>         <input type="radio" name="mon" value="time">between          <select name="firsttime">             <option>time</option>             <option value="12">12:00</option>             <option value="13">13:00</option>             <option value="14">14:00</option>             <option value="15">15:00</option>             <option value="16">16:00</option>             <option value="17">17:00</option>             <option value="18">18:00</option>             <option value="19">19:00</option>             <option value="20">20:00</option>         </select>                  <select name="secondtime">             <option>time</option>             <option value="12">12:00</option>             <option value="13">13:00</option>             <option value="14">14:00</option>             <option value="15">15:00</option>             <option value="16">16:00</option>             <option value="17">17:00</option>             <option value="18">18:00</option>             <option value="19">19:00</option>             <option value="20">20:00</option>         </select>     </td>     <td><input type="radio" name="mon" value="n/a">n/a</td> </tr> 

you can below:

demo

$("input[name=mon]").on("change", function(){     if(this.value=="time"){         alert("first time : " + $('select[name="firsttime"] option:selected').text());         alert("second time : "+$('select[name="secondtime"] option:selected').text());     }  }); 

update

for demo trying values on button click:

$('.getval').on('click',function(){     var selectedoption=$("input[name=mon]:checked").val().trim();     if(selectedoption=="time"){         var dispvalue="first time : " + $('select[name="firsttime"] option:selected').text()+ " , second time : "+$('select[name="secondtime"] option:selected').text();         $('.dispselected').text(dispvalue);      }     else     {         $('.dispselected').text(selectedoption + " has been selected");      }  }); 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -