Asked  2 Years ago    Answers:  5   Viewed   71 times

I noticed that PHP seems to return only values of checked checkboxes. I would like to see a list of checkboxes, not just values of checked checkboxes. Is there a way to detect variables of unchecked boxes?

I asked because I want to be able to update settings. For example, I have a few options that are already checked but if an user decides to uncheck an option, I need to know that unchecked value so I can update the option to be disabled.

 Answers

5

I just ran into this problem myself. I solved it by adding a duplicate hidden field with the same name. When the browser sends this information, the second field overrides the first (so ensure that the hidden field comes first).

<input type="hidden" name="foo" value="">
<input type="checkbox" name="foo" value="bar">

If the checkbox is not checked you get:

$_REQUEST[ 'foo' ] == ""

If the checkbox is checked you get:

$_REQUEST[ 'foo' ] == "bar"
Monday, August 29, 2022
2

Change this:

<td><input type="checkbox" name="all_sizes" value="All">All<br></td>

to this (add the keyword 'checked'):

<td><input type="checkbox" name="all_sizes" value="All" checked>All<br></td>
Monday, August 22, 2022
 
caio
 
1

change

<input type="checkbox" name="txtCheck" value="<?php echo $_POST['txtCheck'];?>"  /><br />

to

<input type="checkbox" name="txtCheck" value="your value" <?php if(isset($_POST['txtCheck'])) echo "checked='checked'"; ?>  /><br />

this will keep checkbox checked..

Friday, December 23, 2022
3

I got this working using the code posted by @rekle as a starting point. The trick is to use NSDirectoryEnumerator, which will do this recursively. Here's the function I wrote in case anyone needs it.

- (NSArray *)recursivePathsForResourcesOfType:(NSString *)type inDirectory:(NSString *)directoryPath{

    NSMutableArray *filePaths = [[NSMutableArray alloc] init];

    // Enumerators are recursive
    NSDirectoryEnumerator *enumerator = [[[NSFileManager defaultManager] enumeratorAtPath:directoryPath] retain];

    NSString *filePath;

    while ((filePath = [enumerator nextObject]) != nil){

        // If we have the right type of file, add it to the list
        // Make sure to prepend the directory path
        if([[filePath pathExtension] isEqualToString:type]){
            [filePaths addObject:[directoryPath stringByAppendingPathComponent:filePath]];
        }
    }

    [enumerator release];

    return [filePaths autorelease];
}

Swift, using NSURL

func recursivePathsForResources(type type: String) -> [NSURL] {

    // Enumerators are recursive
    let enumerator = NSFileManager.defaultManager().enumeratorAtPath(bundlePath)
    var filePaths = [NSURL]()

    while let filePath = enumerator?.nextObject() as? String {

        if NSURL(fileURLWithPath: filePath).pathExtension == type {
            filePaths.append(bundleURL.URLByAppendingPathComponent(filePath))
        }
    }

    return filePaths
}
Saturday, August 6, 2022
 
cephron
 
2

I'm not sure what your HTML looks like, but

$("twitter").attr("id", url);

should probably be:

$(".twitter").attr("id", url);

Update: Try this code... you need to detect if the iframe has loaded as well (demo)

$(function () {
    // define this here because we're changing the ID
    var $twitter = $('#twitter');
    // bind to select inside iframe
    $('#iframe').on('load', function () {
        $(this).contents().find('#cds').change(function () {
            var selectVal = $(this).val();
            url = 'https://twitter.com/intent/tweet?button_hashtag=stream&text=Just enjoying ' + selectVal + ' on';
            $twitter.attr("id", url).text(url);
        }).change(); // trigger change to get initial value
    });
});

Also, since we're changing the ID of twitter, we need to save that jQuery object.

Thursday, November 17, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 

Browse Other Code Languages