JavaScript and client side scripting.
Moderator: General Moderators
Lonestarjack
Forum Commoner
Posts: 31 Joined: Tue Nov 11, 2008 7:13 am
Location: Texas
Post
by Lonestarjack » Mon Jan 14, 2013 12:52 pm
I am trying to set/update a $_SESSION variable based on a radio button being clicked.
Code: Select all
<script type="text/javascript">
$(document).ready (function(){
$(':radio').change (function()
$(':radio[name=list]:nth(0)').attr('checked',true);
{
$_SESSION{'list'} = "Yes";
} else {
$_SESSION{'list'} = "No";
};
});
<input type="radio" name="list" value="Yes">Yes</input>
<input type="radio" name="list" checked value="No">No</input>
</script>
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Mon Jan 14, 2013 12:58 pm
Okay? And?
Lonestarjack
Forum Commoner
Posts: 31 Joined: Tue Nov 11, 2008 7:13 am
Location: Texas
Post
by Lonestarjack » Mon Jan 14, 2013 1:12 pm
Gets an " Uncaught SyntaxError: Unexpected identifier"
$(':radio').change (function()
Sorry about that
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Mon Jan 14, 2013 1:55 pm
You're missing a {. And an "if". And another set of })s.
twinedev
Forum Regular
Posts: 984 Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio
Post
by twinedev » Mon Jan 14, 2013 2:59 pm
and I don't see any PHP Code in that ;-)
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Mon Jan 14, 2013 4:00 pm
twinedev wrote: and I don't see any
PHP Code in that
Ha, I completely passed over that.
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Mon Jan 14, 2013 9:41 pm
Lonestarjack wrote: I am trying to set/update a $_SESSION variable based on a radio button being clicked.
You can't mix Javascript and PHP. You need to populate the Javascript with values when you generate it with PHP, or use an Ajax call to a PHP script to fetch data.
(#10850)
Lonestarjack
Forum Commoner
Posts: 31 Joined: Tue Nov 11, 2008 7:13 am
Location: Texas
Post
by Lonestarjack » Thu Jan 17, 2013 10:22 am
Thanks Christopher
I wrote a generic Ajax program that sets the session variables. Works great.