/    Sign up×
Community /Pin to ProfileBookmark

PHP / Radio Button / Auto save?

Ok.. at my site, users login.

After logging in.. I show them a page with their personal data as well as some public data.. in their personal “area” I want to present an option:

Do you wish to receive emails from us? radio button yes or no.

What I would LIKE to have happen, is anytime they click on the yes or no radio button, their choice will be saved immediately. I guess what I’m after would be something like an ONCHANGE even that would call a PHP script that would write the data to the DB? And I can’t get it figured out…Just not sure how to combine onchange with php? Any thoughts, help AND/OR examples would be GREATLY appreciated…

Thanks!
Ron

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@criterion9Mar 20.2009 — If you want the data to be saved without a page refresh you will need to use AJAX or another async connection to your php script. If you don't mind the whole page refreshing you can use a little javascript onChange handler to "recall" the page.
Copy linkTweet thisAlerts:
@mackilMar 20.2009 — criterion9 is absolutely right. Ajax is probably the preferred method here, but if you don't mind the page refresh (and your users don't either), then you could just pass the checked value over the querystring and catch it with PHP on the refresh.

For Example:
[code=html]
<input type="radio" name="saveme" value="On List" onclick="location.href='<?=$_SERVER["PHP_SELF"]?>?onlist='+this.checked;"> On List<br>
<input type="radio" name="saveme" value="Off List" onclick="location.href='<?=$_SERVER["PHP_SELF"]?>?offlist='+this.checked;"> Off List
[/code]
×

Success!

Help @rjhart 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 4.28,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...