Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

jQuery variable pass to PHP variable

Links for php scripts

Moderators: macek, egami, gesf

jQuery variable pass to PHP variable

Postby shobe089 » Mon Aug 08, 2011 10:35 pm

hello there. i am having a hard time to debug this problem of mine.i am supposed to retrieve the value from my jQuery and save it in a PHP variable.
$(document).ready(function()
{
$("#months").change(function(event)
{
$.ajax
({
type: 'post',
url: "monthly_CRD.php",
data:
{
"m": $(this).val()
},
success: function(msg)
{
alert(msg);
},
error: function(msg)
{
alert("An error happened: " +msg);
}
});
});

<div>
<select id="months">
<option value='00'>Month...</option>
<option value='01'>Jan</option>
<option value='02'>Feb</option>
<option value='03'>Mar</option>
<option value='04'>Apr</option>
</select>
</div>

<?php
if (isset($_POST['m']))
{
$m = $_POST['m'];
echo $m;
}
?>

it keeps on giving me An error happened: [objectXMLHttpRequest] in my alert box
please i need this badly.i've been working on this for about 1 week already.i'm new with jQuery so please bare with me.
shobe089
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Aug 08, 2011 10:26 pm

Re: jQuery variable pass to PHP variable

Postby egami » Tue Aug 09, 2011 4:51 am

JQuery = Client
PHP = Server.

In order to get it from jQuery, you'll have to make a post/get to the server, then PHP can retrieve it. It won't happen on initial page load.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: jQuery variable pass to PHP variable

Postby egami » Tue Aug 09, 2011 4:52 am

You can however use AJAX to post the code on the same page, saving whatever it is you're looking for as a SESSION variable.

I don't have time nor the exact knowledge on how to do it, but I am fairly certain that's your only option.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: jQuery variable pass to PHP variable

Postby shobe089 » Tue Aug 09, 2011 5:08 pm

my jQuery is already working fine.now i just want to display the retrieved value and echo it on PHP once the drop down is used.how would i do that?
shobe089
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Aug 08, 2011 10:26 pm


Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.