temujinleal Posted January 9, 2008 Share Posted January 9, 2008 good day!! my problem is, i wanted to automatically toggle back my last checked application if two checkboxes are checked.. here's the code.. <script language="javascript"> function toggleDiv(divid) { if(document.getElementById(divid).style.display == 'none') { document.getElementById(divid).style.display = 'block'; } else { document.getElementById(divid).style.display = 'none'; } } function keepCount() { var NewCount = 0 if (document.check_box.facility1.checked) { NewCount = NewCount + 1 } if (document.check_box.facility2.checked) { NewCount = NewCount + 1 } if (NewCount == 2) { alert('Pick Just One Please') document.check; return false; } } </script> <form name="check_box"> <input name="facility1" type="checkbox" value="Rooms" onclick="toggleDiv('rooms_r'); return keepCount();" /> <input name="facility2" type="checkbox" value="Conference Rooms" onclick="toggleDiv('conf_rooms'); return keepCount();" /> <div id="rooms_r" style="display:none">sample</div> <div id="conf_rooms" style="display:none">another sample</div> </form> thanks in advance!! sorry for my grammar if you can't understand.. the code that i've posted is complete.. i just want some idea how to change it... thanks! Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted January 9, 2008 Share Posted January 9, 2008 <script language="javascript"> function toggleDiv(divid) { if(document.getElementById(divid).style.display == 'none') { document.getElementById(divid).style.display = 'block'; } else { document.getElementById(divid).style.display = 'none'; } } function keepCount(divid) { var NewCount = 0 if (document.check_box.facility1.checked) { NewCount = NewCount + 1 } if (document.check_box.facility2.checked) { NewCount = NewCount + 1 } if (NewCount == 2) { alert('Pick Just One Please'); document.getElementById(divid).style.display='none'; document.check; return false; } } </script> <form name="check_box"> <input name="facility1" type="checkbox" value="Rooms" onclick="toggleDiv('rooms_r'); return keepCount('rooms_r');" /> <input name="facility2" type="checkbox" value="Conference Rooms" onclick="toggleDiv('conf_rooms'); return keepCount('conf_rooms');" /> <div id="rooms_r" style="display:none">sample</div> <div id="conf_rooms" style="display:none">another sample</div> </form> Quote Link to comment Share on other sites More sharing options...
temujinleal Posted January 10, 2008 Author Share Posted January 10, 2008 sir thank you for the tweak! sir another question.. what will it be if i'm going to make it radio button with the same name and everytime i will change the selection, the previous toggle will automatically display none? thanks!! Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted January 11, 2008 Share Posted January 11, 2008 it should work out fine; this exact way - just switch out checkboxes for radio button and you should be good to go Quote Link to comment Share on other sites More sharing options...
temujinleal Posted January 11, 2008 Author Share Posted January 11, 2008 thank you sir for the help and tips!! i really appreciate your kindness!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.