Ich benutze Ajax, um meine Auswahlbox zu machen, aber die zweite Auswahlbox zeigte keinen Wert, wenn ich die 1. Auswahlbox wähle. Wie kann ich den Wert in der 2. Auswahlbox anzeigen?Auswahlbox basierend auf einem anderen Auswahlfeld Wert php
index.php (jQuery):
$(document).ready(function(){
$('#brand').on('change',function(){
var brand = $(this).val();
if(brand){
$.ajax({
type:'POST',
url:'ajax_city.php',
data:'brand='+brand,
success:function(html){
$('#outlet').html(html);
}
});
}else{
$('#outlet').html('<option value="">Select OUTLET first</option>');
}
});
});
index.php (HTML/PHP)
<select class="brand" style="width:200px" id="brand" name="brand" >
<?php $i = 0;
while (!$br->EOF) {
$fv = $br->Fields("mBrand");
$name = $fv->value;
echo '<option value="' . trim($name) . '"><b>' . $name . '</b></option>';
$br->MoveNext();
}
?>
</select>
<input type="hidden" name="loc" id="loc">
</td>
</div>
<li class="form-line" id="id_19">
<label class="form-label-left" id="label_19" for="input_19"> Outlet </label>
<div id="cid_20" class="form-input">
<br><br>
<select class="outlet" name="outlet" id="outlet" style="width:200px" >
<option value="">--Select outlet--</option>
</select>
ajax_city.php:
if(isset($_POST["brand"])&&!empty($_POST["brand"]))
{
$brand=$_POST['brand'];
$rb = $itdeptconn->Execute("SELECT DISTINCT mOutlet FROM [IT_Dept].[dbo].[mstOutlet] WHERE mBrand='".$brand."'");
//$sql=mysql_query("select b.id,b.data from data_parent a,data b where b.id=a.did and parent='$id'");
echo '<option value="">Select Outlet</option>';
while (!$rb->EOF) {
$fv = $rb->Fields("mOutlet");
$name = $fv->value;
echo '<option value="' . trim($name) . '"><b>' . $name . '</b></option>';
$rb->MoveNext();
}
}
?>
Alle Fehler-Konsole? – Rasclatt
Versuchen Sie in Ihrem Ajax: 'data: {" brand ": brand},' – Rasclatt
@Rasclatt keine Fehleranzeige. – Jazlyn