I have the following, I would like to add a feature that will allow me to click the image displayed and checkbox above becomes checked, is it possible? Seems lines 29-32. I found an example, but didn't work for me.
thanks
<html>
<head>
<title>This is a simple PHP script to delete select images.</title>
</head>
<body>
<?php
if (isset($_POST['image_list'])) {
foreach ($_POST['image_list'] as $imagename) {
if (file_exists($imagename)) {
unlink($imagename);
}
}
}
?>
<form action="images_view.php" method="POST">
<p>Please select multiple images you want to remove. Please note that the selected images will be removed from server as well.</p>
<?php
$files = glob("videos/THUMBNAILS/*.*");
for ($i=0; $i<count($files); $i++)
{
$image = $files[$i];
$supported_file = array(
'jpg',
);
$ext = strtolower(pathinfo($image, PATHINFO_EXTENSION));
if (in_array($ext, $supported_file)) {
echo '<input type="checkbox" name="image_list[]" style="margin-right:10px;" value="'.$image.'" />';
echo '<input type="checkbox" name="image_list[]" style="margin-right:10px;" value="'.$image.'" />';
echo basename($image)."<br />"; // show only image name if you want to show full path then use this code // echo $image."<br />";
echo '<img src="'.$image .'" style="max-width: calc(100% - 20px); alt="Random image" />'."<br /><br />";
} else {
continue;
}
}
?>
<input type="submit" name="submit" style="width:300px;height:60px;margin-left:20px;" value="Delete" />
</form>
</body>
</html>
You can just wrap the checkbox input and the image by a label:
<label>
<input type="checkbox" name="image_list[<?php echo $imageId; ?>]" />
<img src="https://lh3.googleusercontent.com/ez8pDFoxU2ZqDmyfeIjIba6dWisd8MY_6choHhZNpO0WwLhICu0v0s5eV2WHOhuhKw=w170" />
</label>
Demo
In backend you can simply do a foreach and delete the according images:
foreach (array_keys($_POST['image_list']) as $imageId) {
// delete image by id.
}
Related
<script>
function tikla()
{
//var radio=document.getElementById('radio').value;
var d2=document.getElementById('buton').value;
alert(d2);
}
</script>
<?php
for($i=1;$i<5;$i++)
{?>
<form>
<?php echo $i; ?>
<input type="text" name="txt" value="<?php echo $i; ?>" disabled="disabled" />
<input type="button" id="buton" value="<?php echo $i; ?>" onclick="tikla(this.value)" />
</form>
<?php }?>
In PHP, I want to send button or text values to Javascript but I can send only one value. I can't see other loop values.
Is it really the intention to have multiple forms? There is no reason why not of course but you can accomplish what you need, generally speaking, using a single form.
By using a nodelist you can iterate through and assign event listeners separately to the HTML - inline event handlers are considered old school nowadays. In this example the event handler is assigned to each button and simply alerts the numeric value assigned to the button ( as in your example ) and also the value and type of the text field to show how you might access it if required.
A quick demo
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8' />
<title>JS Func</title>
<style>
fieldset{border:none;margin:1rem auto}
</style>
</head>
<body>
<form>
<?php
for( $i=1; $i<5; $i++ ) {
$rand = rand(1,99);
?>
<fieldset>
<?php echo $i; ?>
<input type='text' name='txt[]' value='<?php echo $i * $rand; ?>' />
<input type='button' value='<?php echo $i; ?>' />
</fieldset>
<?php
}
?>
</form>
<script>
Array.prototype.slice.call( document.querySelectorAll( 'form > fieldset > input[type="button"]' ) ).forEach( function( bttn ){
bttn.addEventListener('click', function(event){
alert( this.value +' '+this.previousElementSibling.value + ' ' +this.previousElementSibling.tagName )
}, false );
})
</script>
</body>
</html>
pass values in function
<script>
function tikla(val)
{
//var d2=document.getElementById('buton').value;
alert(val);
}
</script>
<?php
for($i=1;$i<5;$i++)
{?>
<form>
<?php echo $i; ?>
<input type="text" name="txt" value="<?php echo $i; ?>" disabled="disabled" />
<input type="button" id="buton" value="<?php echo $i; ?>" onclick="tikla(<?php echo $i; ?>)" />
</form>
<?php }?>
Hello I am new to Javascript and currently trying to update another developers code. I have a very simple 4 question for with a mix of checkboxes and text fields.
My first piece of Javascript works: it says if there is no info typed in postsitesurvey then alert that it must be filled out. The next step I am stuck on. The employee has 2 visible options and 1 hidden. Were parts left over? I want it that if he checks yes then the next field which is the Left with field must be filled out and if not yes then he can go ahead and submit the form. Any help would be appreciated.
echo "<form id=\"myForm\" name=\"myForm\" method=\"post\" action=\"edit.php?
action=upbill2\" onsubmit=\"return validateForm()\">";
echo "<table width=\"100%\" border=\"0\" cellspacing=\"5\" cellpadding=\"0\"
class=\"table2\">";
echo "<div class=\"col-sm-6\">";
echo "<b>Post Site Survey</b>";
Echo "   ";
echo "<textarea style=\"width:70%\" name=\"postsitesurvey\"
id=\"postsitesurvey\" value=\"$postsitesurvey\" />";
echo $postsitesurvey;
echo "</textarea>";
echo "</div>";
echo "<div class=\"col-sm-6\">";
echo "<b>Was There Equipment Left Over?</b>";
Echo "   ";
echo "<input name=\"eq_left\" type=\"checkbox\" id=\"eq_left_yes\"
value=\"1\"";
if ($eq_left == "1") { echo " checked=\"checked\" "; }
echo "/>    Yes ";
Echo "   ";
echo "<input name=\"eq_left\" type=\"checkbox\" id=\"eq_left_no\"
value=\"2\"";
if ($eq_left == "2") { echo " checked=\"checked\" "; }
echo "/>    No ";
echo "</div>";
echo "<input name=\"eq_left\" type=\"checkbox\" id=\"eq_left_empty\"
value=\"\" style=\"display:none;\" checked";
if ($eq_left == "") { echo " checked=\"checked\" "; }
echo "</div>";
echo "<div class=\"col-sm-6\">";
echo "<b>Left with?</b>";
Echo "   ";
echo "<input style=\"width:45%\" name=\"eq_poc_\" type=\"text\"
id=\"eq_poc\" value=\"$eq_poc\" placeholder=\"Name of customer\"";
echo "</div>";
echo "    or";
Echo "   ";
echo "<input name=\"eq_poc\" type=\"checkbox\" id=\"chkNo\" value=\"MCS\"";
if ($eq_poc == "MCS") { echo " checked=\"checked\" "; }
echo "/>    MCS";
echo "</div>";
echo "<br>";
echo "<div class=\"col-sm-12 text-center\">";
echo "<input name=\"st_id\" type=\"hidden\" id=\"st_id\" value=\"3\" />";
echo "<input name=\"job_id\" type=\"hidden\" id=\"job_id\" value=\"$job_id\" />";
echo "<input type=\"submit\" name=\"Submit\" value=\"Submit\" class=\"btn btn-primary\"/>";
echo "</div>";
echo "</table>";
echo "</form>";
}
----JAVASCRIPT----
function validateForm() {
var x = document.forms["myForm"]["postsitesurvey"].value;
if (x == "") {
alert("Post site survey must be filled out");
return false;
}
I removed the distracting stuff, you can copypaste to your question, I will then delete this post...
<?php
$checked_1 = ($eq_left == "1") ? 'checked="checked"' : '';
$checked_2 = ($eq_left == "2") ? 'checked="checked"' : '';
$checked_3 = ($eq_left == "") ? 'checked="checked"' : '';
$checked_4 = ($eq_poc == "MCS") ? 'checked="checked"' : '';
?>
<form id="myForm" name="myForm" method="post" action="edit.php?action=upbill2" onsubmit="return validateForm()">
<b>Post Site Survey</b>
<textarea name="postsitesurvey" id="postsitesurvey" value="$postsitesurvey" />
<?=$postsitesurvey?>
</textarea>
<b>Was There Equipment Left Over?</b>
<input name="eq_left" type="checkbox" id="eq_left_yes" value="1" <?=$checked_1?>/>
<input name="eq_left" type="checkbox" id="eq_left_no" value="2" <?=$checked_2?>/>
<input name="eq_left" type="checkbox" id="eq_left_empty" value="" style="display:none;" <?=$checked_3?>/>
<b>Left with?</b>
<input name="eq_poc_" type="text" id="eq_poc" value="$eq_poc" placeholder="Name of customer"/>
<b>or</b>
<input name="eq_poc" type="checkbox" id="chkNo" value="MCS" <?=$checked_4?>/><b>MCS</b>
<input name="st_id" type="hidden" id="st_id" value="3" />
<input name="job_id" type="hidden" id="job_id" value="<?=$job_id?>" />
<input type="submit" name="Submit" value="Submit" class="btn btn-primary"/>
</form>
I think something like this would work for you. I changed your checkboxes to radio buttons and removed the eq_left = "". You also had two fields with the name "eq_poc". You cannot do this. I removed one, but you may want to consider a different option or explain what you are trying to do a bit better.
I have also added a toggleHide() function to show or hide the customer name field.
Alert messages can be annoying, so I removed them and added a <div> to put error messages on the page in red color.
One other thing to note is that I added the required attribute to your textarea. This allows the browser to inform the user that they haven't filled in a required field. Doing it this way, however, will not show the error message on the page in red. So, depending how you want to implement it, you may want to remove the required attribute.
The following code below will work by itself, once you are happy with it, remove the two lines at the top that are for testing and see if it works with variables passed from your other code.
<?php
//The two lines below are for testing purposes only. Once you are done testing, you can remove them to implement it with the rest of your code.
$eq_left = "1";
$eq_poc = "";
$checked_yes = ($eq_left == "1") ? 'checked="checked"' : '';
$checked_no = ($eq_left == "2") ? 'checked="checked"' : '';
?>
<html>
<script>
function toggleHide() {
var equipment_left = document.getElementById('eq_left_yes').checked;
if (equipment_left){
document.getElementById('leftwith').style.display = 'block';
}
else {
document.getElementById('leftwith').style.display = 'none';
}
}
function validateForm() {
var message = "";
var postsitesurvey = document.getElementById('postsitesurvey').value;
if (postsitesurvey == "") {
message = "Post site survey must be filled out";
}
else if (equipment_left && eq_poc == ""){
var equipment_left = document.getElementById('eq_left_yes').checked;
var eq_poc = document.getElementById('eq_poc').value;
message = "Customer name must be filled in";
}
if (message != ""){
document.getElementById('message').textContent = message;
return false;
}
return true;
}
</script>
<style>
.formfield {
font-weight: bold;
}
#leftwith {
display: none;
}
#message {
color: red;
}
</style>
</body>
<form id="myForm" name="myForm" method="post" action="edit.php?action=upbill2" onsubmit="return validateForm()">
<div class="formfield">Post Site Survey</div>
<textarea name="postsitesurvey" id="postsitesurvey" value="$postsitesurvey" required="required" /><?php echo $postsitesurvey ?></textarea>
<div class="formfield">Was There Equipment Left Over?
<input name="eq_left" type="radio" id="eq_left_yes" value="1" onclick="toggleHide()" <?php echo $checked_yes ?> /> Yes
<input name="eq_left" type="radio" id="eq_left_no" value="2" onclick="toggleHide()" <?php echo $checked_no ?> /> No
</div>
<div class="formfield" id="leftwith">
Left with?
<input name="eq_poc_" type="text" id="eq_poc" value="<?php echo $eq_poc ?>" placeholder="Name of customer"/>
</div>
<input name="st_id" type="hidden" id="st_id" value="3" />
<input name="job_id" type="hidden" id="job_id" value="<?php echo $job_id ?>" />
<div id="message"></div>
<input type="submit" name="Submit" value="Submit" class="btn btn-primary"/>
</form>
<script>
toggleHide();
</script>
</body>
</html>
This is my code here I can't get image name to store in a database, and I can't see image preview also when it selected.
add_action('admin_footer',array(&$this,'media_selector_print_scripts'));
public function media_selector_settings_page_callback(){
if(isset($_POST['submit_image_selector'])&&
isset($_POST['image_attachment_id'])):
update_option('media_selector_attachment_id',absint($_POST['image_attachment_id']));
endif;
wp_enqueue_media();
if(isset($_POST['submit'])){
$category = $_POST['category'];
$type = $_POST['type'];
$name = $_POST['name'];
$description = $_POST['description'];
$img_path = get_option('media_selector_attachment_id');
$insert_data = new insert_Data();
$insert_data-
>insert_table_data($category,$type,$name,$description,$img_path);
}
?>
WordPress setting page design HTML
<h1>Plugin page</h1>
<form method="post" action="" enctype="multipart/form-data">
<br><br><br>
<input type="text" name="category" placeholder="category"/><br><br>
<input type="text" name="type" placeholder="type"/><br><br>
<input type="text" name="name" placeholder="name"/><br><br>
<textarea name="description" placeholder="description"></textarea>
<br><br>
<div class="img-preview-wrapper">
<img id="img-preview" src="<?php echo
wp_get_attachment_url(get_option('media_selector_attachment_id')); ?>"
height="100px"/>
</div>
<input id="upload_image_button" type="button" class="button" value="<?php _e('Upload image'); ?>"/>
<input type="hidden" name="image_attachment_id" id="image_attachment_id" value="<?php echo get_option('media_selector_attachment_id'); ?>"/>
<input type="submit" name="submit" value="Save" class="button-primary"/>
</form>
<?php
}
this is jquery script
public function media_selector_print_scripts(){
$my_saved_attachment_post_id = get_option('media_selector_attachment_id',0);
?>
<script type="text/javascript">
jQuery(document).ready(function($){
//uploading files
var file_frame;
var wp_media_post_id = wp.media.model.settings.post.id;//store the old id
var set_to_post_id = <?php echo $my_saved_attachment_post_id;?>;
jQuery('#upload_image_button').on('click', function (event) {
event.preventDefault();
//if the media frame already exists, reopen it
if (file_frame){
//set the post id to what we want
file_frame.uploader.uploader.param('post_id', set_to_post_id);
//open frame
file_frame.open();
return;
} else {
wp.media.model.settings.post.id = set_to_post_id;
}
//create the media frame
file_frame = wp.media.frames.file_frame = wp.media({
title: 'Select a image to upload',
button: {
text: 'Use this image',
},
multiple:false
});
file_frame.on('select', function () {
attachment =
file_frame.state().get('selection').first().toJSON();
$('#image-preview').attr('src',attachment.url).css('width','auto');
$('#image-attachment-id').val(attachment.id);
wp.media.model.settings.post.id = wp_media_post_id;
});
file_frame.open();
});
jQuery('a.add-media').on('click', function(){
wp.media.model.settings.post.id = wp_media_post_id;
});
});
</script>
<?php
}
This is my code here I can't get image name to store in a database, and I can't see image preview also when it selected.This is my code here I can't get image name to store in a database, and I can't see image preview also when it selected.This is my code here I can't get image name to store in a database, and I can't see image preview also when it selected.
In php file you have a check for isset($_POST['submit_image_selector']) but I don't see such a field in html.
Try to replace it with isset($_POST['submit']).
I am trying to toggle results i have echo'd out of table but i am having no luck.
I have tried the same code in HTML and it works perfectly.
Ive been working on this for a while now, and was wondering if someone could point me in the right direction.
What I've tired
Adding the javascript inside the php echo.
Adding a counter to the id, to make it unique on loop
Placing each line of the echo results in echo(""); tags.
adding a counter, to make the id unique on loop.
PHP
$i = 1;
while ($output = $fc_sel->fetch_assoc()) {
$fc_run .= $output['Food_Cat_name'] . $output['Food_Cat_Desc'] . '<br>';
$_SESSION['Food_Cat_name'] = $output['Food_Cat_name']; //echo out product name
$_SESSION['Food_Cat_Desc'] = $output['Food_Cat_Desc']; //echo out product desc
echo"
<div id='first_product'>
<button onclick='toggle_visibility('tog')'>Toggle</button>
<div id='tog'>
<div id='red_head'>
<p id='menu_title' class ='hidden' onclick='toggle_visibility('tog')'> Add your first menu item</p>
</div>
<h3 id='menu'>Menu Section</h3>
<form name='first_prod' id='first_prod' enctype='multipart/form-data' action='testing.php' method='POST' accept-charset='utf-8' >
<label id='cat_label' name='cat_label'>Name</label>
<input type='text' id='cat_name' name='cat_name' value=''>
<label id='desc_label' name='desc_label'>Description</label>
<input type='text' id='cat_desc' name='cat_desc' value=''>
</form>
</div>
</div>
";
}
}
JAVASCRIPT
<script>
//turn entire div into toggle
function toggle_visibility(id) {
var e = document.getElementById(id);
if (e.style.display == 'block' || e.style.display == '')
e.style.display = 'none';
else
e.style.display = 'block';
}
</script>
The single quotes in onclick='toggle_visibility('tog')' are conflicting with the outer single quotes. So either escape them or use double quotes in either the outer pair or the inner pair.
Then in PHP, remove the <?php echo. Just put the HTML in PHP. The echo only complicates things. If you need dynamic data in your HTML, just inject it at that place with <?php ... ?>. But so far I haven't seen any of that in your HTML: it is static.
Here is a working snippet, after having made that change in two places:
//turn entire div into toggle
function toggle_visibility(id) {
var e = document.getElementById(id);
if (e.style.display == 'block' || e.style.display == '')
e.style.display = 'none';
else
e.style.display = 'block';
}
<div id='first_product'>
<button onclick="toggle_visibility('tog')">Toggle</button>
<div id='tog'>
<div id='red_head'>
<p id='menu_title' class ='hidden' onclick="toggle_visibility('tog')"> Add your first menu item</p>
</div>
<h3 id='menu'>Menu Section</h3>
<form name='first_prod' id='first_prod' enctype='multipart/form-data' action='testing.php' method='POST' accept-charset='utf-8' >
<label id='cat_label' name='cat_label'>Name</label>
<input type='text' id='cat_name' name='cat_name' value=''>
<label id='desc_label' name='desc_label'>Description</label>
<input type='text' id='cat_desc' name='cat_desc' value=''>
</form>
</div>
</div>
Edit after modification of the question
The code in the question was extended so the HTML is produced in a loop now.
You should now take care to produce unique id values only. So you'll probably want to add <?=$i?> at several places, like this:
<?php
session_start();
// ....
$i = 1;
while ($output = $fc_sel->fetch_assoc()) {
$fc_run .= $output['Food_Cat_name'] . $output['Food_Cat_Desc'] . '<br>';
$_SESSION['Food_Cat_name'] = $output['Food_Cat_name'];
$_SESSION['Food_Cat_Desc'] = $output['Food_Cat_Desc'];
?>
<div id='first_product<?=$i>'>
<button onclick="toggle_visibility('tog<?=$i>')">Toggle</button>
<div id='tog<?=$i>'>
<div id='red_head<?=$i>'>
...etc. Note that the PHP was closed before the HTML output started. Do this, instead of a large echo. Then at the end of it, open PHP tag again to end the loop:
<?php
}
?>
please modify your code
echo "
<div id='first_product'>
<button onclick='toggle_visibility(\"tog\")'>Toggle</button>
<div id='tog'>
<div id='red_head'>
<p id='menu_title' class ='hidden' onclick='toggle_visibility(\"tog\")'> Add your first menu item</p>
</div>
<h3 id='menu'>Menu Section</h3>
<form name='first_prod' id='first_prod' enctype='multipart/form-data' action='testing.php' method='POST' accept-charset='utf-8' >
<label id='cat_label' name='cat_label'>Name</label>
<input type='text' id='cat_name' name='cat_name' value=''>
<label id='desc_label' name='desc_label'>Description</label>
<input type='text' id='cat_desc' name='cat_desc' value=''>
</form>
</div>
</div>
"
<button value='tog' onclick='toggle_visibility(this)'>Toggle</button>
Just use "this" and assign value to button its working
Try this ;)
<?php
$i = 1;
while($output = $fc_sel->fetch_assoc()){
$fc_run .= $output['Food_Cat_name'] . $output['Food_Cat_Desc'] . '<br>';
$_SESSION['Food_Cat_name'] = $output['Food_Cat_name']; //echo out product name
$_SESSION['Food_Cat_Desc'] = $output['Food_Cat_Desc']; //echo out product desc
?>
<div id="first_product<?php echo $i; ?>">
<button onclick="javascript:toggle_visibility('tog<?php echo $i; ?>')">Toggle</button>
<div id="tog<?php echo $i; ?>">
<div id="red_head<?php echo $i; ?>">
<p id="menu_title<?php echo $i; ?>" class ="hidden" onclick="toggle_visibility('tog<?php echo $i; ?>')"> Add your first menu item</p>
</div>
<h3 id="menu<?php echo $i; ?>">Menu Section</h3>
<form name="first_prod" id="first_prod<?php echo $i; ?>" enctype="multipart/form-data" action="testing.php" method="POST" accept-charset="utf-8">
<label id="cat_label<?php echo $i; ?>" name="cat_label">Name</label>
<input type="text" id="cat_name<?php echo $i; ?>" name="cat_name" value="">
<label id="desc_label<?php echo $i; ?>" name="desc_label">Description</label>
<input type="text" id="cat_desc<?php echo $i; ?>" name="cat_desc" value="">
</form>
</div>
</div>
<?php
$i++;
}
?>
I have a user edit page with a set of user permissions. Each permission is basically a checkbox. If checked the user has the permission if unchecked the user does not have the permission. So if I want to remove a permission I would uncheck the box and vice versa to add a permission.
I got everything to work using a hidden input, but the problem that I am having is that it is submitting both the hidden input and the checkbox value. For example even if I don't make a change and click the update button, I get a message that reads:
Removed access from 1 permission levels
Added access to 1 permission levels
I will show you my code below. Something to keep in mind is that each input calls a different function.
Here is the inputs:
<ul class="list-group permission-summary-rows">
<?php //List of permission levels user is apart of
foreach ($permissionData as $v1) {
if(isset($userPermission[$v1['id']])){
?>
<li class="list-group-item">
<?php echo $v1['name']; ?>
<span class="pull-right">
<input type="hidden" name="removePermission[<?php echo $v1['id'] ?>]" id="removePermission[<?php echo $v1['id'] ?>]" value="<?php echo $v1['id'] ?>" >
<input type="checkbox" checked data-toggle="switch" name="addPermission[<?php echo $v1['id'] ?>]" id="addPermission[<?php echo $v1['id'] ?>]" value="<?php echo $v1['id'] ?>" >
</span>
</li>
<?php
}
}
?>
<?php //List of permission levels user is not apart of
foreach ($permissionData as $v1) {
if(!isset($userPermission[$v1['id']])){
?>
<li class="list-group-item">
<?php echo $v1['name']; ?>
<span class="pull-right">
<input type="checkbox" data-toggle="switch" name="addPermission[<?php echo $v1['id'] ?>]" id="addPermission[<?php echo $v1['id'] ?>]" value="<?php echo $v1['id'] ?>" >
</span>
</li>
<?php
}
}
?>
Here is the PHP:
//Remove permission level
if(!empty($_POST['removePermission'])) {
$remove = $_POST['removePermission'];
if ($deletion_count = removePermission($remove, $userId)) {
$successes[] = lang("ACCOUNT_PERMISSION_REMOVED", array ($deletion_count));
} else {
$errors[] = lang("SQL_ERROR");
}
}
// Add permission level
if(!empty($_POST['addPermission'])) {
$add = $_POST['addPermission'];
if ($addition_count = addPermission($add, $userId)) {
$successes[] = lang("ACCOUNT_PERMISSION_ADDED", array ($addition_count));
} else {
$errors[] = lang("SQL_ERROR");
}
}
Even if I add the hidden input underneath the checkbox input I receive the same message. I know it has something to do with using different functions so can anyone guide me in the right direction? Should I use some JS code to find if it is checked or not?
If you want to use that trick... you must to name the same both arrays!
<input type="hidden" name="Permission[<?php echo $v1['id'] ?>]" id="removePermission[<?php echo $v1['id'] ?>]" value="0" >
<input type="checkbox" <?php echo ($v1['id']=='YES')?'checked':'' ?> data-toggle="switch" name="Permission[<?php echo $v1['id'] ?>]" id="AddPermission[<?php echo $v1['id'] ?>]" value="1" >
Take a look at "$v1['id']=='YES'" and use the correct comparison. Remember, name must be the same and a value of 0 will be disabled and 1 enabled.
Good luck.
Both the hidden input and the checkbox values are submitted because they're of different input types.
You don't need to hardcode checked explicitly. Write a php if loop to check if the user has permission and echo "checked" accordingly.
//EDIT:
This is the code I would use for this problem. Just overwrite all rules for the user in the DB. Only thing you have to know is the amount of rules (represented by the constant).
<html>
<body>
<?PHP
define("NUMBEROFINPUTS",5);
if(isset($_GET["permissions"])){
$dbperms = array();
foreach($_GET["permissions"] as $permission) {
$dbperms[$permission] = 1;
}
//$dbperms: 0->Input is not set; 1-> Input is set
for($i=0;$i<NUMBEROFINPUTS;$i++){
if(isset($dbperms[$i])) {
echo "Input ".$i." is set<br />";
}
else{
echo "Input ".$i." is not set<br />";
}
}
}
else {
echo '<form>';
for($i = 0;$i<NUMBEROFINPUTS;$i++){
echo 'Permission '.$i.': <input type="checkbox" name="permissions[]" value="'.$i.'" checked /><br />';
}
echo '<input type="submit" /></form>';
}
?>
</body>
</html>
I hope I could help.
use this in jQuery
$("input[type=checkbox]:not(:checked)").attr("value");
well for get and do some with all unchecked checkbox you can collect it into array... and send it on submit to server
var aUnchecked = new Array();
$("input[type=checkbox]:not(:checked)").each(fucntoin(){
aUnchecked.push($(this).attr("name"));
}