/    Sign up×
Community /Pin to ProfileBookmark

Checkbox Default Value

This is more of a simple HTML question, but I thought some of my fellow php devs might have run into this. I’m passing two arrays with POST. The first is an item[] and the second is received[]. So it looks like this:

[U]Item[/U] [U]Received[/U]
1 checked
2 checked
3
4 checked

However, since they are passed as an array, #3 in the above example will be skipped as checkboxes do not have a default value so the passed results will look like this:

[U]Item[/U] [U]Received[/U]
1 checked
2 checked
3 checked
4

Any suggestions on how to work around this?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 29.2006 — Assign a value to each checkbox, then you can tell which have been checked:
[code=php]
<?php // sample checkbox form ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>
<label><input type="checkbox" name="check[]" value="test1">Test 1</label><br>
<label><input type="checkbox" name="check[]" value="test2">Test 2</label><br>
<label><input type="checkbox" name="check[]" value="test3">Test 3</label><br>
<input type="submit" name="submit" value="Submit">
</p>
</form>
<?php
if(isset($_POST['submit']))
{
echo "<p>You checked:</p>n<pre>";
print_r($_POST);
echo "</pre>n";
}
?>
[/code]
Copy linkTweet thisAlerts:
@Doc_ThirstauthorNov 30.2006 — Perhaps I could give it the value of the item id, however, it's dynamic in size so it might get a bit tricky. Perhaps my error is trying to accomplish the update all in one statement, if I do the update then approach the received in it's own foreach statement...Gonna check it out, I'll hollar back.
Copy linkTweet thisAlerts:
@Doc_ThirstauthorNov 30.2006 — Yep that was the ticket...

<input type=checkbox name=received[] value=$id>

update page:

foreach($_POST['received'] as $record)

{

$receivedstatment = "update polineitems set received = '1' WHERE (id = '$record')";

mssql_query($receivedstatment, $handle);

}

Simple, just needed to [s]talk[/s] type it out. Thanks again NogDog
×

Success!

Help @Doc_Thirst spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...