I have this problem and at wits end can't work out the issue alone please help.
JavaScript: ( external but tried it in the main html as well)
$('#customer-select').on('change',function() {
var self =$(this);
$.ajax({
url: ' type: 'GET',
data: { customer: self.val() },
success: function(data) {
$('#customer-profile').html(data);
},
error:function(xmlHttpRequest, textStatus, errorThrown) {
alert(errorThrow);
}
});
});
PHP file:
<?php
require 'start.php'
if(isset($_GET['customer'])) {
$customersQuery = "
SELECT
customernumber,
company,
notactive
FROM customerequipment
WHERE customernumber = :customer_id
";
$customer = $db->prepare($customersQuery);
$customer->execute(['customer_id'=> $_GET['company']]);
$selectedCustomer = $customer->fetch(PDO::FETCH_ASSOC);
}
}
HTML file:
The browser is finding the scripts but I include them anyway
<script src="js/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/global.js"></script>
<script src="assets/jquery-2.1.3.min.js"></script>
<div class="col-xs-2">
<?php
$customerequipmentQuery = "
SELECT
customernumber,
company,
notactive
FROM customerequipment
WHERE notactive = 0
";
$customers = $db->query($customerequipmentQuery);
?>
<labelCustomerlabel>
<select type="text" list="customer" id="customer-select"
name="customer" style = "height:35px; width: 200px;"/>
<option value="">None Selected</option>
<?php foreach($customers->fetchAll() as $customer): ?>
<option value="<?php echo $customer['customernumber']; ?>">
<?php echo $customer['company']; ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div id="customer-profile" >
<p>
testing
</p>
</div>
My database connect is working because I populate other dropdown boxes without ajax.
I want to use ajax because I need to GET a record based on the value from a dropdown/textbox. If there are different/better methods perhaps a suggestion would help.
JavaScript: ( external but tried it in the main html as well)
$('#customer-select').on('change',function() {
var self =$(this);
$.ajax({
url: ' type: 'GET',
data: { customer: self.val() },
success: function(data) {
$('#customer-profile').html(data);
},
error:function(xmlHttpRequest, textStatus, errorThrown) {
alert(errorThrow);
}
});
});
PHP file:
<?php
require 'start.php'
if(isset($_GET['customer'])) {
$customersQuery = "
SELECT
customernumber,
company,
notactive
FROM customerequipment
WHERE customernumber = :customer_id
";
$customer = $db->prepare($customersQuery);
$customer->execute(['customer_id'=> $_GET['company']]);
$selectedCustomer = $customer->fetch(PDO::FETCH_ASSOC);
}
}
HTML file:
The browser is finding the scripts but I include them anyway
<script src="js/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/global.js"></script>
<script src="assets/jquery-2.1.3.min.js"></script>
<div class="col-xs-2">
<?php
$customerequipmentQuery = "
SELECT
customernumber,
company,
notactive
FROM customerequipment
WHERE notactive = 0
";
$customers = $db->query($customerequipmentQuery);
?>
<labelCustomerlabel>
<select type="text" list="customer" id="customer-select"
name="customer" style = "height:35px; width: 200px;"/>
<option value="">None Selected</option>
<?php foreach($customers->fetchAll() as $customer): ?>
<option value="<?php echo $customer['customernumber']; ?>">
<?php echo $customer['company']; ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div id="customer-profile" >
<p>
testing
</p>
</div>
My database connect is working because I populate other dropdown boxes without ajax.
I want to use ajax because I need to GET a record based on the value from a dropdown/textbox. If there are different/better methods perhaps a suggestion would help.