Jump to content

Add select all checkboxes to php


ratt831

Recommended Posts

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">

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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' />';

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

 
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.