0

I have a query here that I use 2 select boxes and here I got the value changed over 2nd select box after first select box value has been selected. The first select box is for Projects and the second one is for modules. The modules are changed as per the project is changed. So here I got the value of modules. My query is I want the value of module into a PHP variable. Here is my code,

<script src="js/jquery-1.8.3.min.js"></script>
<script>
$(document).ready(function() {  

$("#state-list option").filter(function() {    
       return $(this).val() == $("#mm").val(); 
    }).attr('selected', true);  

$("#state-list").live("change", function() {

$("#mm").val($(this).find("option:selected").attr("value"));
var val = $("#mm").val();
alert("val===="+val);
});
}); 
</script>

<?php
$module_id= var val; //(if this is possible on any how then please help me out.)

$sql_host = 'localhost';
$sql_user = "root";
$sql_pass = "";
$sql_data = "abc";
// Opens a connection to a MySQL server
$connection = mysql_connect ($sql_host, $sql_user, $sql_pass);

// Set the active MySQL database
$db_selected = mysql_select_db($sql_data, $connection);
$qyrey="select * from tblamount where moduleid='$module_id'";
mysql_query($qyrey) or die('error');
?>

How I can get the value of script variable value into a PHP variable. Means "var val variable value into PHP variable $module_id"? How this will be possible.

Kamal Hasija
  • 59
  • 11
  • `$("#state-list").on("change",function() { $.get("storevar.php",{ "module_id",this.value});` – mplungjan Jun 27 '17 at 08:00
  • Dear sir, I don't understand @mplungjan, will you please explain in brief. how this code is written or executed in the file, please help me out. – Kamal Hasija Jun 27 '17 at 08:04
  • see the duplicate. You can add the code I posted to the function in document.ready. You will need another PHP or reuse the same and test that $_GET["module_id"] is set – mplungjan Jun 27 '17 at 08:08
  • please help me out anyone here, because I don't get the proper solution. I have to finish this task today asap. – Kamal Hasija Jun 28 '17 at 07:14
  • hey @mplungjan, sir please help me, any other solution for passing the value of textbox into a variable in PHP by using any technique PHP+JS+JQuery+Ajax or whatever. Note: We have to pass the value to a variable without the click in submit or any button. – Kamal Hasija Jun 28 '17 at 07:22
  • I did. You need to use AJAX onchange of the select. Remember JavaScript runs on the client and PHP on the server – mplungjan Jun 28 '17 at 09:30

0 Answers0