javascript - Show/hide textfile depending on radio buttons' selection -


i know repeated question, cannot make run. tried solutions found here in , googling...

i have radio button form in page. want when user selects 'only 1 attendee' option text field appears option. if user selects 1 dissapears.

normal form

once user selects only one option, text box appears.

expanded form

i've been trying doing javascript. use piece of code

<script>     $(document).ready(function()         $("#send_to_one").hide();         $("input:radio[name="people"]").change(function(){             if(this.checked){             if(this.value =='one'){               $("#send_to_one").show()             }else{               $("#send_to_one").hide();             }          }     }   }); </script> 

the form's code is

  <div id="send_to">     <input type="radio" id="send_poll" name="people" value="all" checked="checked">all attendees</br>           <input type="radio" id="send_poll" name="people" value="one" >only 1 attendee<br/>     <div id="send_to_one">       <label>write attendee's name: </label><input type="text" id="attendeename"><br/><br/>     </div>     <input type="radio" id="send_poll" name="people" value="group">a group of attendees</br>                 </div>     

i've checked javascript files loaded. tried putting javascript code inside html.erb file form is, in separated .js file , in application.htm.erb's <head></head> section, no luck. where need put each part of code in order work?

using rails 3.0.4, ruby 1.8.9. i'm using jquery

live demo

html:

<div id="send_to">   <input type="radio" id="send_poll" name="people" value="all" checked="checked" />all attendees<br/>         <input type="radio" id="send_poll" name="people" value="one" />only 1 attendee<br/>   <div id="send_to_one">       <label>write attendee's name: </label><input type="text" id="attendeename" /><br/><br/>   </div>   <input type="radio" id="send_poll" name="people" value="group" />a group of attendees<br/>               </div> 

jq:

$(document).ready(function(){      $("#send_to_one").hide();      $("input:radio[name='people']").change(function(){                if(this.value == 'one' && this.checked){               $("#send_to_one").show();             }else{               $("#send_to_one").hide();             }      });  }); 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -