ratt831 Posted March 10, 2010 Share Posted March 10, 2010 I have this PHP and it works great, just want to add a select all button and reset I am not that good at php can I get some help please? THANK YOU for the help in advance <?php $currentdir = getcwd(); chdir("/****/*************/**/*****/*/*/**"); $grmx= 'Music '; $filelist = glob("*.mp3"); if(empty($filelist)) { echo "Sorry DIR is loading new songs at this time..."; } else { echo "<form action=\"****************\" method=\"POST\">\n"; echo "$grmx<br />\n"; echo "<div style=\"height:200px;width:400px;overflow:auto;font-size: small;Arial, Helvetica, sans-serif;color: #0066FF;border:1px solid #99CCFF;\">\n"; foreach($filelist AS $file) { if(is_file($file)) { echo "<input type=\"checkbox\" name=\"checkfiles[]\" value=\"$file\">$file<br />\n"; } } echo "</div>\n"; echo "<button type=\"submit\">Load Player</button>\n"; echo "</form>\n"; } chdir("$currentdir"); ?> <body style="color: #0066FF"> Quote Link to comment https://forums.phpfreaks.com/topic/194711-add-select-all-checkboxes-to-php/ Share on other sites More sharing options...
teamatomic Posted March 10, 2010 Share Posted March 10, 2010 Use JS. http://www.shiningstar.net/articles/articles/javascript/checkboxes.asp HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/194711-add-select-all-checkboxes-to-php/#findComment-1023980 Share on other sites More sharing options...
ratt831 Posted March 10, 2010 Author Share Posted March 10, 2010 Use JS. http://www.shiningstar.net/articles/articles/javascript/checkboxes.asp HTH Teamatomic Thank you but I just wanted to add it in PHP right to this script if possible? I don't know much about PHP so really hope its possible? Quote Link to comment https://forums.phpfreaks.com/topic/194711-add-select-all-checkboxes-to-php/#findComment-1023990 Share on other sites More sharing options...
teamatomic Posted March 10, 2010 Share Posted March 10, 2010 Then add a submit button named checkall or something and have your script add a selected to each box. Quote Link to comment https://forums.phpfreaks.com/topic/194711-add-select-all-checkboxes-to-php/#findComment-1023993 Share on other sites More sharing options...
greatstar00 Posted March 10, 2010 Share Posted March 10, 2010 isnt it suppose to be "checked"? like this echo '<input type="checkbox" name='ch1' checked='true' />'; echo '<input type="checkbox" name='ch1' checked='true' />'; echo '<input type="checkbox" name='ch1' checked='true' />'; echo '<input type="checkbox" name='ch1' checked='true' />'; Quote Link to comment https://forums.phpfreaks.com/topic/194711-add-select-all-checkboxes-to-php/#findComment-1024011 Share on other sites More sharing options...
teamatomic Posted March 10, 2010 Share Posted March 10, 2010 Yea, but more like this echo '<input type="checkbox" name='ch1[]' checked='true' />'; echo '<input type="checkbox" name='ch1[]' checked='true' />'; echo '<input type="checkbox" name='ch1[]' checked='true' />'; echo '<input type="checkbox" name='ch1[]' checked='true' />'; HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/194711-add-select-all-checkboxes-to-php/#findComment-1024013 Share on other sites More sharing options...
ratt831 Posted March 10, 2010 Author Share Posted March 10, 2010 Yea, but more like this echo '<input type="checkbox" name='ch1[]' checked='true' />'; echo '<input type="checkbox" name='ch1[]' checked='true' />'; echo '<input type="checkbox" name='ch1[]' checked='true' />'; echo '<input type="checkbox" name='ch1[]' checked='true' />'; HTH Teamatomic Sorry I am sort of confused? I just want to add a button that says select all? It already shows all the boxes without checks. Can this be added to the script? And if so can you show me what to add? Quote Link to comment https://forums.phpfreaks.com/topic/194711-add-select-all-checkboxes-to-php/#findComment-1024033 Share on other sites More sharing options...
teamatomic Posted March 10, 2010 Share Posted March 10, 2010 I already told you how but you dont want to do it. So look at me second post. Add another submit button that has a name like "checkall" or something similar. Then when you are checking the form data and figure out its submitted from the "checkall" button you rebuild the form widgets with the checked="true" part added to them. If this confuses you and seems like a bunch of unneeded work, then refer back to my first suggestion, which is the proper way to check and uncheck a group of form elements. HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/194711-add-select-all-checkboxes-to-php/#findComment-1024087 Share on other sites More sharing options...
Psycho Posted March 10, 2010 Share Posted March 10, 2010 Just to pile on to what Teamatomic is saying: PHP does not do any client-side, real-time functionality such as checking/unchecking checkboxes, enabling/disabling fields, etc., etc. The only way you could do it with PHP is to have the user submit the page (such as a "check all" button as teamatomic stated) and then determine the action the user selected and then resend the page to the user with the appropriate controls modified. It's a waste of time and the it will be a poor experience for the user. Client-side functionality such as this is exactly what JavaScript is for. Quote Link to comment https://forums.phpfreaks.com/topic/194711-add-select-all-checkboxes-to-php/#findComment-1024093 Share on other sites More sharing options...
ratt831 Posted March 10, 2010 Author Share Posted March 10, 2010 I already told you how but you dont want to do it. So look at me second post. Add another submit button that has a name like "checkall" or something similar. Then when you are checking the form data and figure out its submitted from the "checkall" button you rebuild the form widgets with the checked="true" part added to them. If this confuses you and seems like a bunch of unneeded work, then refer back to my first suggestion, which is the proper way to check and uncheck a group of form elements. HTH Teamatomic Sorry thanks mjdamatoOh I do understand Now. As I took another look I think it would be better if the form started with all the boxes checked. So My prob is I really need them all selected .If you look at my script can you just tell me how and what to change to make it that all checkboxes are all already selected in the form instead of empty boxes I think that will solve my issue? I don't know if your allowed to show you what I am trying to fix on my site I just want to make it simpler to select. So when you click the directories they will all be selected will help me a lot. http://gremx.com Thanks So Much Quote Link to comment https://forums.phpfreaks.com/topic/194711-add-select-all-checkboxes-to-php/#findComment-1024094 Share on other sites More sharing options...
Psycho Posted March 10, 2010 Share Posted March 10, 2010 echo "<input type=\"checkbox\" name=\"checkfiles[]\" value=\"$file\" checked=\"checked\" />$file<br />\n"; Quote Link to comment https://forums.phpfreaks.com/topic/194711-add-select-all-checkboxes-to-php/#findComment-1024097 Share on other sites More sharing options...
ratt831 Posted March 10, 2010 Author Share Posted March 10, 2010 echo "<input type=\"checkbox\" name=\"checkfiles[]\" value=\"$file\" checked=\"checked\" />$file<br />\n"; Thank You Quote Link to comment https://forums.phpfreaks.com/topic/194711-add-select-all-checkboxes-to-php/#findComment-1024101 Share on other sites More sharing options...
ratt831 Posted March 10, 2010 Author Share Posted March 10, 2010 echo "<input type=\"checkbox\" name=\"checkfiles[]\" value=\"$file\" checked=\"checked\" />$file<br />\n"; Thank You Is it possible I Can pay you to write it to work the other way you seem to know php? To include select the first 100 listed and reset buttons? Actually I would only need it to select the first 100 only not all. Because some directories have thousands of selections and that would cause problems. The first 100 would be perfect. Quote Link to comment https://forums.phpfreaks.com/topic/194711-add-select-all-checkboxes-to-php/#findComment-1024103 Share on other sites More sharing options...
Psycho Posted March 10, 2010 Share Posted March 10, 2010 I responded to you in the PM you sent. What you are asking seems pretty simple, and I would be happy to do it for you. But, before I do anything let me know exactly what you want done so I can see what would be involved. Also, there are other problems with your script that shoud be addressed. For instance you are creating output before your BODY tag. Quote Link to comment https://forums.phpfreaks.com/topic/194711-add-select-all-checkboxes-to-php/#findComment-1024255 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.