0

Hello,
I have a php variable $birthday, I am showing it's value like this:

<div id= "dob" class="pick_number">Day of Birth: <?php echo $birthday ?></div>
<div id="test"></div> // value should be printed back in here.

I need to pass the value of $birthday via ajax, I had the following but it seems not working, no value is printed back in test div:

var $birthday =$('#dob'); // to select the above code

$.get("process.php", 
    {birthday: $birthday},
    function(chart) {
    $test.text(chart);
});

Thanks.

2
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by rse
0

I'm not sure, but I don't think javascript likes a dollar sign at the start of a variable name (i.e. $birthday). Also, i'm assuming you're using jquery, so $test.text(chart) should be $('#test').text(chart). Try this:

var birthday = $('#dob');

$.get("process.php", 
    {birthday: birthday},
    function(chart) {
    $('#test').text(chart);
});

Hope this helps :)

Edited by PlyrJames791: n/a

0

Hi Thanks for your reply,
It did not like it without the $:

var birthday = $('#dob'); // it hangs

var $birthday= $('#dob'); // did not hang but did not print back anything

I tried this:

var birthdayStr = $birthday.val().replace(/[^0-9\-]+/g,''); 
$.get("process.php", 
		{birthday: birthdayStr},
		function(chart) {
				$test.text(chart);
			});

it printed empty value: birthday is:
Any ideas?

0

In the first line, you should use text() or html() instead of val() since it isn't a form element. If that doesn't work, you could try this:

var birthdayStr = $('#dob').html().replace(/[^0-9\-]+/g,'');
$("#test").load("process.php", { birthday: birthdayStr } );
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.