javascript - Get value of twitter bootstrap radio button group in Meteor -


i know the're lot of topics around this, unfortunately, can't find working solution. here's question.

i have meteor template following button group in it:

<template name="test">  <form class="form-horizontal" id="search_form">  <fieldset>   <div class="form-actions">      <div class="btn-group" data-toggle="buttons-radio" id="my_radiogroup">       <button type="radio" class="btn my_button" name="knop" value="1">or</button>       <button type="radio" class="btn my_button" name="knop" value="2">and</button>     </div>     </div>   </fieldset>  </form> </template> 

now want value of selected radiobutton (or or and). therefore tried following solutions, based on find on web , on stack:

first solution:

template.test.events({  'click #my_radiogroup' : function(e,t) {  var element = t.find('button:radio[name=knop]:checked');   alert($(element).val()); } }); 

second solution (based on active class twitter bootstrap):

template.test.events({  'click #my_radiogroup' : function(e,t) {  var element = t.find("#my_button.active").value;  alert(element); } }); 

i've tried third solution changes in template:

<input type="hidden" id="alignment" value="" />   <div class="btn-group alignment" data-toggle="buttons-radio">  <button type="button" class="btn">or</button>  <button type="button" class="btn">and</button> </div> 

and code in *.js file:

template.test.events({  'click #alignment.btn' : function(e,t) {  var element = val(this.text());  alert(element);  return false; } }); 

however, none of solutions works. wants how can value of selected radiobutton?

thanks.

in last example you're trying target element both id #alignment , .btn class, don't exists.

also don't know "t" from, event map passed event (the "e").

this code should work (not tested though).

template.test.events({   'click .btn' : function(e) {     var clickedbutton = e.currenttarget;     alert( $(clickedbutton).val() );   } }); 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -