/    Sign up×
Community /Pin to ProfileBookmark

Checkbox – auto form submit?

Hi,

I have the following part of a script:

[code=php] if ($row[‘9’] == ‘Y’) {
echo ‘<input type=”checkbox” name=”approved” value=”Y” checked />’;
}
else {
echo ‘<input type=”checkbox” name=”approved” value=”Y” />’;
}
[/code]

Now this displays a checked checkbox when the value equals ‘Y’ and unchecked if it’s anything else.

Now I wonder, is it easy to set an auto-submit on this checkbox so if its unchecked it does an automatic UPDATE query to make a value equal to ‘N’.
Or if it’s checked, to make it ‘Y’ if checked.

Thanks for any help.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@scragarFeb 13.2008 — it's possible, however it's unset if it's not checked from the server(and PHPs) point of view, so even changing it's value to 'N' on the client side would have no effect, since a checkbox with a value of 'N' that's unchecked still doesn't pass a value.
Copy linkTweet thisAlerts:
@invisionauthorFeb 13.2008 — OK. Don't quite understand what you meant there.

If originally checked, then unchecked(which auto-submits), it would do an UPDATE query to set the value to N.

If originally unchecked, then checked(which auto-submits), it would do an UPDATE query to set the value to Y.
Copy linkTweet thisAlerts:
@invisionauthorFeb 15.2008 — This could be a case for NogDog ?

OK, so the idea is that once checked/unchecked it will set the value in my db to 'Y' or 'N' respectively.

[code=php] # user.php
if ($row['9'] == 'Y') {
?>
<input type="checkbox" name="approved" value="Y" checked onClick="this.form.action='user.php';this.form.submit()" />
<?
}
else {
?>
<input type="checkbox" name="approved" value="Y" onClick="this.form.action='user.php';this.form.submit()" />
<?
}
[/code]

Basically I need an UPDATE query to change 'N' or 'Y' values.

IF UNCHECKED IS CHECKED {

UPDATE users WHERE id=$id VALUE = Y

}

--OR--

IF CHECKED IS UNCHECKED {

UPDATE users WHERE id=$id VALUE = N

}
×

Success!

Help @invision 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.27,
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,
)...