0

Can some body help me get the current value from this option tag to account.php as a session variable or anything ..

// loadsubcat.php This code is for dependent dropdown

$query = mysql_query("SELECT * FROM table_cmsjob WHERE VesselID= {$parent_cat}");
while($row = mysql_fetch_array($query))
    {
    echo "<option value='$row[jobName]'>$row[jobName]</option>";
    }

var javascriptVariable = $('#sub_cat').val(); 

I know this can be solve using ajax but I don't know how.

I will use the javascript variable as a reference for a couple of checkboxes under it but first must be passed as a php variable.

1

1 Answer 1

1

you ajax will look like this,

$.ajax({
            type: 'POST',
            url: "account.php",// path to ajax file
            data: {javascriptVariable:javascriptVariable},// you can pass values here in key value pairs.
            success: function(data) {
                alert(data);

            }
        });

You can send n number of key => value pairs.

like

parent_cat:100

Next:

echo $_POST['javascriptVariable'];  // <--- grabbing ajax data here


$query = mysql_query("SELECT * FROM table_cmsjob WHERE VesselID= {$parent_cat}");
while($row = mysql_fetch_array($query))
{
echo "<option value='$row[jobName]'>$row[jobName]</option>";
}

what ever echoed in php file will come in ajax success data,

alert(data) will alert what you had echoed in php. you can use that in your html file.

Sign up to request clarification or add additional context in comments.

3 Comments

hey sir may I ask if I use the code above and replace url with my page account.php and data with my javascriptvariable? can I now grab the data using either $_REQUEST or $_POST
change this line in ajax, data: javascriptVariable , to data: {javascriptVariable:javascriptVariable} ,
in php use $_POST['javascriptVariable']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.