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.

Manwal
  • 23,450
  • 12
  • 63
  • 93
  • 1
    Possible duplicate of [jQuery Ajax POST example with PHP](http://stackoverflow.com/questions/5004233/jquery-ajax-post-example-with-php) – T3 H40 Nov 23 '15 at 06:50

1 Answers1

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.

Niranjan N Raju
  • 12,047
  • 4
  • 22
  • 41