vincea Posted February 1, 2007 Share Posted February 1, 2007 I am creating a newsletter management system and what I want it to do is list all the subscribers and their email addresses from the database. Beside each, a checkbox.. when the checkbox is "checked" it will add onto a string that will be the complete recipient list. Right now I have if the box gets checked (with an "onchange") it will put that box value (email address) into a textbox. If Unchecked it will remove the e-mail from the textbox. here is some code: function getChecks() { count = document.nl_subs.elements.length; for (i=0; i < count; i++) { if(document.nl_subs.elements[i].checked == true) { document.getElementById("recipients").value += document.nl_subs.elements[i].value + ","; } } } I know this is way off.. cuz right now it is getting ALL the checkboxs that are checked and adding them into the textbox. Here is the html & php: $sub_check is the number (1, 2, 3 etc) <input type="checkbox" name="sub_check<? echo $sub_check ?>" value="<? echo $email ?>" onchange="getChecks()"/> I tried using the getChecks(this.name) do just do the ONE checkbox but i couldnt get it to work. so for the ONE checkbox i had something like: function getChecks(element) { checkbox = document.nl_subs.element; if(document.nl_subs.checkbox.checked == true) { document.getElementById("recipients").value += document.nl_subs.element.value + ","; } } any help is appreciated. Link to comment https://forums.phpfreaks.com/topic/36701-checkboxes-driving-me-nuts/ Share on other sites More sharing options...
effigy Posted February 1, 2007 Share Posted February 1, 2007 What if someone unchecks and rechecks the box? <script language="javascript" type="text/javascript"> function getChecks(obj) { if (obj.checked) { document.getElementById("recipients").value += obj.value + ","; } } </script> <form name="nl_subs"> <input type="checkbox" value="1" name="test_1" onchange="getChecks(this)" /> <input type="checkbox" value="2" name="test_2" onchange="getChecks(this)" /> <input type="checkbox" value="3" name="test_3" onchange="getChecks(this)" /> <textarea id="recipients"></textarea> </form> Link to comment https://forums.phpfreaks.com/topic/36701-checkboxes-driving-me-nuts/#findComment-175014 Share on other sites More sharing options...
tomfmason Posted February 1, 2007 Share Posted February 1, 2007 Also, in the future you should try to pick a more descriptive topic for your posts. It makes it easier for people to see if they know anything that may help. I generally skip over posts with vague topics. Good luck, Tom Link to comment https://forums.phpfreaks.com/topic/36701-checkboxes-driving-me-nuts/#findComment-175067 Share on other sites More sharing options...
vincea Posted February 2, 2007 Author Share Posted February 2, 2007 What if someone unchecks and rechecks the box? <script language="javascript" type="text/javascript"> function getChecks(obj) { if (obj.checked) { document.getElementById("recipients").value += obj.value + ","; } } </script> <form name="nl_subs"> <input type="checkbox" value="1" name="test_1" onchange="getChecks(this)" /> <input type="checkbox" value="2" name="test_2" onchange="getChecks(this)" /> <input type="checkbox" value="3" name="test_3" onchange="getChecks(this)" /> <textarea id="recipients"></textarea> </form> thanks that works great and cleans up my ugly code but still I need it when the checkbox is Unchecked now remove it from the text box or string so it isn't part of the mass email Link to comment https://forums.phpfreaks.com/topic/36701-checkboxes-driving-me-nuts/#findComment-175399 Share on other sites More sharing options...
effigy Posted February 2, 2007 Share Posted February 2, 2007 Why not have a "finalize" type button that loads up the elements before submitting? Is the click on/click off interactivity really needed? Link to comment https://forums.phpfreaks.com/topic/36701-checkboxes-driving-me-nuts/#findComment-175416 Share on other sites More sharing options...
vincea Posted February 2, 2007 Author Share Posted February 2, 2007 Why not have a "finalize" type button that loads up the elements before submitting? Is the click on/click off interactivity really needed? Good idea.. i don't know why i always make things so difficult to begin with.. I will try that. Thanks again. Link to comment https://forums.phpfreaks.com/topic/36701-checkboxes-driving-me-nuts/#findComment-175576 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.