php - Disable/enable Codeigniter input field with jquery -


i have following code input fields:

echo form_label('name :', "first_name[0]"); echo form_input("first_name[0]", set_value("first_name[0]")); echo form_error("first_name[0]"); 

this outputs following html code:

<label for="first_name[0]"> name: </label> <input type="text" name="first_name[0]" value> 

this part of form accommodates 2-5 participants. idea have 2 name fields @ least active, while other 3 disabled default , can activate them checkbox. not jquery , unable accomplish this. possible jquery again, clear input if checkbox selected activate field, , unchecked after that?

i'm not sure, believe looking (jsfiddle):

<div class="participant">   <label for="first_name[0]"> name: </label>   <input type="text" name="first_name[0]" value> </div> <div class="participant">   <label for="first_name[0]"> name: </label>   <input type="text" name="first_name[0]" value> </div> <div class="participant">   <label for="first_name[0]"> name: </label>   <input type="text" name="first_name[0]" value> </div> <div class="participant">   <label for="first_name[0]"> name: </label>   <input type="text" name="first_name[0]" value> </div> <div class="participant">   <label for="first_name[0]"> name: </label>   <input type="text" name="first_name[0]" value> </div> <button id="add-participant">   add </button> 

js

$(".participant:gt(1)").addclass("hidden"); $("#add-participant").on("click", function() {     $(".participant.hidden").first().removeclass("hidden");   if(!$(".participant.hidden").length) {     $(this).hide();   } }); 

only first 2 visible @ first, can click button add more... 5.

or... better... starting single participant , creating more if needed... ability remove.

jsfiddle


Comments