Pass an attribute from JQuery to PHP (on event)?

Hello, first I want to point that I’m using jQWidgets.
I want to pass an attribute from jquery to a PHP file. Now, I’ve tried using $.post.
Like this:

[code]$(’#problemiTree’).bind(‘select’, function (event) {
var item3 = $(’#problemiTree’).jqxTree(‘getSelectedItem’);
if (item3 && item3.parentId!=0)
dataAdapter4.dataBind();
$.post(
“problemiOblastData.php”,
{ selectedItem: item3.label }

            );[/code]

In the PHP file I test with:
[php]if (isset($_POST[‘selectedItem’]))
echo ‘yes’;
else
echo ‘no’;[/php]

Maybe I’m not testing correctly. I use a direct link to the php file to check echo.
I’ve tried using $.ajax, but the result is the same.

Thanks.

I am pretty new at this stuff too so bear with me but don’t you want to pass a value to the php not a label?

Also don’t you need the source of where the value is coming from so I think it should be something like

$.post('problemiOblastData.php', { selectedItem: form_name.item3.value}

where form_name is the name of the form on the initial page that the data is entered into.

There is no form where the data is entered into because I need to pass the element which the user selects from a tree. Label is fine because I need that text which is shown in the tree (that’s label if I’m not mistaken).
That’s why I use .bind(‘select’,…).

I’ve figured out what was the problem. I passed item.label (or item), where I should have passed item.id. mySQL query in the php file requires that id, and it won’t work with label etc…

Sponsor our Newsletter | Privacy Policy | Terms of Service