Skip to content

Instantly share code, notes, and snippets.

@rushdimohamed09
Created January 18, 2017 18:09
Show Gist options
  • Save rushdimohamed09/75866b883fca49f85fb9cdd67eeae83f to your computer and use it in GitHub Desktop.
Save rushdimohamed09/75866b883fca49f85fb9cdd67eeae83f to your computer and use it in GitHub Desktop.
<?php
require_once ('../Connection/connection.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery Populate City Dropdown Based on Country Selected</title>
<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("select.CARD").change(function(){
var selectedCountry = $(".CARD option:selected").val();
$.ajax({
type: "POST",
url: "test111.php",
data: { CARD : selectedCountry }
}).done(function(data){
$("#response").html(data);
});
});
});
</script>
<script type="text/javascript">
function myCreateFunction() {
var table = document.getElementById("myTable");
var row = table.insertRow(0);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.innerHTML = "<td><label>Card:</label><select class='CARD' name='card[]'> <option>Select</option> <?php $sql1 = 'SELECT * FROM mstock order by id asc'; $result1 = $conn->query($sql1); if ($result1->num_rows > 0) { while($row1 = $result1->fetch_assoc()) { echo '<option value='.$row1['card'].'>'.$row1['card'].'</option>'; } } ?></select></td>";
cell2.innerHTML = "<td id='response'><!--Response will be inserted here--></td>";
}
function myDeleteFunction() {
document.getElementById("myTable").deleteRow(0);
}
</script>
</head>
<body>
<form method="post" action="222.php">
<input type="button" value="Add" name="add" onclick="myCreateFunction()" />
<input type="button" value="Del" onclick="myDeleteFunction()" />
<table id="myTable">
<tr>
</tr>
</table>
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>
<?php
require_once ('../Connection/connection.php');
if(isset($_POST["CARD"])){
// Capture selected CARD
$CARD = $_POST["CARD"];
// Display city dropdown based on CARD name
if($CARD !== 'Select'){
echo "<label>Quantity:</label>";
echo "<select name='qty[]'>";
$sql1 = 'SELECT qty FROM mstock where card = "'.$CARD.'" order by id asc'; $result1 = $conn->query($sql1); if ($result1->num_rows > 0) { while($row1 = $result1->fetch_assoc()) { echo '<option value='.$row1['qty'].'>'.$row1['qty'].'</option>'; } }
echo "</select>";
$sql1 = 'SELECT qty FROM mstock where card = "'.$CARD.'" order by id asc'; $result1 = $conn->query($sql1); if ($result1->num_rows > 0) { while($row1 = $result1->fetch_assoc()) { echo '<label>'.$row1['qty'].'</label>'; } } ;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment