javascript - Why are my hidden divs auto appearing? -


i have 2 hidden divs named hidden_div , hidden_divx. objective make each 1 appear when respective checkbox clicked. have 2 separate functions. both pretty identical. first hidden div works fine. second 1 auto appears. thoughts or suggestions?

js:

function doinput(obj){     var checkboxs = $("input[type=checkbox]:checked");      var =0, box;     $('#hidden_div').fadeout('fast');      while(box = checkboxs[i++]){         if(!box.checked)continue;         $('#hidden_div').fadein('fast');         break;     } }  function doinputs(obj){     var checkboxs = $("input[type=checkbox]:checked");      var =0, box;     $('#hidden_divx').fadeout('fast');      while(box = checkboxs[i++]){         if(!box.checked)continue;         $('#hidden_divx').fadein('fast');         break;     } } 

and here current html:

<div id="ticket_hidden" style="text-align: center; clear:both;">     <div id="visible_div" style="float: left;">         <input type="checkbox" name="escalated" value="yes" onclick="doinput(this)" tabindex="18">escalate&nbsp;&nbsp;&nbsp;     </div>     <div id="hidden_div" style="float: left;">         <input type="text" id="escalated_to" name="escalated_to" maxlength="100" style="width:200px; height:18px;" tabindex="19" placeholder="escalated to">     </div>     <br />     <div id="visible_divx" style="float: left;">         <input type="checkbox" name="escalated" value="yes" onclick="doinputs(this)" tabindex="20">send email&nbsp;&nbsp;&nbsp;     </div>     <div id="hidden_divx" style="float: left;">         <input type="text" id="escalated_to" name="escalated_to" maxlength="100" style="width:200px; height:18px;" tabindex="21" placeholder="email to">     </div> </div> 

you should grab checked value obj since you're passing in this doinputs(this).

function doinput(obj) {     if ($(obj).is(':checked')) {         $('#hidden_div').fadein('fast');     } else {         $('#hidden_div').fadeout('fast');     } }  function doinputs(obj) {     if ($(obj).is(':checked')) {         $('#hidden_divx').fadein('fast');     } else {         $('#hidden_divx').fadeout('fast');     } } 

jsfiddle: http://jsfiddle.net/dv2kb/1/


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -