Page 1 of 1

Jquery selects

Posted: Mon Jan 14, 2013 12:52 pm
by Lonestarjack
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>

Re: Jquery selects

Posted: Mon Jan 14, 2013 12:58 pm
by requinix
Okay? And?

Re: Jquery selects

Posted: Mon Jan 14, 2013 1:12 pm
by Lonestarjack
Gets an " Uncaught SyntaxError: Unexpected identifier"

$(':radio').change (function()

Sorry about that

Re: Jquery selects

Posted: Mon Jan 14, 2013 1:55 pm
by requinix
You're missing a {. And an "if". And another set of })s.

Re: Jquery selects

Posted: Mon Jan 14, 2013 2:59 pm
by twinedev
and I don't see any PHP Code in that ;-)

Re: Jquery selects

Posted: Mon Jan 14, 2013 4:00 pm
by requinix
twinedev wrote:and I don't see any PHP Code in that ;-)
Ha, I completely passed over that.

Re: Jquery selects

Posted: Mon Jan 14, 2013 9:41 pm
by Christopher
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.

Re: Jquery selects

Posted: Thu Jan 17, 2013 10:22 am
by Lonestarjack
Thanks Christopher
I wrote a generic Ajax program that sets the session variables. Works great.