html - jQuery onclick toggle function -


i have following foundation toggle element:

<div class="switch radius">   <input id="x" name="switch-x" type="radio" onclick="$(this).revealprofile('no');"checked>   <label for="x">no</label>    <input id="x1" name="switch-x" type="radio" onclick="$(this).revealprofile('yes');">   <label for="x1">yes</label>   <span></span> </div> 

when clicked change input boolean value of hidden field true false:

<input id="real_property_sale_reveal_owner_profile" name="real_property_sale[reveal_owner_profile]" type="hidden" value="false">  

i've written following functions achieve this:

$.fn.revealprofile = function(no) {     $('input#real_property_sale_reveal_owner_profile').val('false'); }; $.fn.revealprofile = function(yes) {     $('input#real_property_sale_reveal_owner_profile').val('true'); }; 

however, last function runs when toggle clicked: $.fn.revealprofile = function(yes) instead of alternating between two. going wrong?

change

$.fn.revealprofile = function(no) {     $('input#real_property_sale_reveal_owner_profile').val('false'); }; $.fn.revealprofile = function(yes) {     $('input#real_property_sale_reveal_owner_profile').val('true'); }; 

to

$.fn.revealprofile = function(boolyesno) {     var valuetoset = false;     if(boolyesno == 'yes'){         valuetoset = true;     }     $('input#real_property_sale_reveal_owner_profile').val(valuetoset); }; 

the reason last function running because defined them both on same property revealprofile prototype running recent function set. better approach above passing parameter instead.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -