Passing jquery variable to PHP
-
Hello, I have a list of dropdown options for a survey, and am counting their choices using jquery. The counting code works fine and has been confirmed. The trouble comes with passing the variable to PHP (from what I’ve read, I’ll need to use the POST function but am having trouble) in order to modify the user’s meta data based on the survey responses.
Here’s the jquery / counting code which works fine:
$('select').change(function() { // get all selects var eSelects = $('select.e'); // set values count by type var eyes = 0; // for each select increase count $.each(eSelects, function(i, s) { // increase count if($(s).val() == '1') { eyes++; } }); // update count values summary $('.cnteyes').text(eyes); });
And here’s the PHP which is not working (don’t understand how to use the POST function, so left that out):
<?php $response = 'cnteyes'; if ( ! add_user_meta( get_current_user_id(), 'survey', $response, true ) ) { update_user_meta ( get_current_user_id(), 'survey', $response ); } echo get_user_meta( get_current_user_id(), 'survey', true ); ?>
Any help would be greatly appreciated! I’m completely stuck and do not understand how to pass jquery to PHP. Thanks for your time.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Passing jquery variable to PHP’ is closed to new replies.