2016-12-29 9 views
0

Hier ist mein Code.Wie Sie den ausgewählten Wert in ComboBox abrufen und für die zweite ComboBox-Abfrage verwenden

Ich habe mehrere ComboBoxen. Ich muss Wert aus in ComboBox ausgewählt und Wert in anderen Abfrage verwenden. Alle Daten, die ich aus Oracle auswähle.

Dies ist mein erster ComboBox und ich brauche Wert dieser ComboBox Option in Abfrage der zweiten ComboBox zu verwenden. Ich meine zweite ComboBox hängt von der ersten Auswahl ab.

Wie kann ich "Value" bekommen? Ich habe versucht, onchange="this.form.submit()" zu verwenden, aber es aktualisiert die Seite und verliert meine wählen. Vielleicht ist es möglich, es mit Ajax zu tun ...

<tr> 
 
\t <div class="form-group" style="background-color:#f9f9f9;border:1px solid #ddd;border-radius:4px;padding:2px;"> 
 
\t <label>Something:</label><span style="color:#FF0000;">*</span></label> 
 
\t 
 
\t \t <select class="form-control" input-sm name="example" required> \t \t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t \t \t \t 
 
\t \t \t <OPTION VALUE="">Choose any</OPTION> 
 
\t \t \t \t \t \t \t \t \t \t \t \t 
 
\t \t \t <OPTION VALUE="first">first_name</OPTION> 
 
\t \t \t <OPTION VALUE="second">second_name</OPTION> 
 
\t \t \t \t \t \t \t \t \t \t 
 
\t \t \t </select> 
 
\t </div> 
 
</tr>

Antwort

0

Ich habe neue PHP-Datei mit dem Namen "js_post.php". Wenn wir wählten eine Option aus dem ersten ComboBox-, JavaScript-Wert Senden an „js_post.php“ und dort Code cheking Wert und hängt von Wertauswahloption.

<?php 
 
if(isset($_POST["action"]) && $_POST["action"]="get_data" && isset($_POST["muracietnov_id1"]) && $_POST["muracietnov_id1"] !="") 
 
{ 
 

 
\t if($_POST["muracietnov_id1"]==1) 
 
\t { 
 
\t \t 
 
//```````````````````````HERE SHould be your connection to DB```````````````` 
 
$select_query= sqlsrv_query($connection,$query); 
 
\t \t \t \t \t \t \t \t \t \t \t 
 
while($result=sqlsrv_fetch_array($select_query) 
 
{ 
 
\t \t \t \t \t \t \t \t \t \t \t 
 
echo '<OPTION VALUE="'.$result['DATAID'].'">'.$result['NAME'].'</OPTION>'; 
 
\t \t \t \t \t \t \t \t \t \t 
 
} 
 

 
\t } 
 
?>

Dies ist Javascript und HTML, die ich verwendet.

$("#muracietnov_id").change(function(){ 
 
\t var url = 'js_post.php'; 
 
\t var muracietnov_id=$("#muracietnov_id").val(); 
 
\t var posting = $.post(url, { 'action': 'get_data','muracietnov_id1': muracietnov_id}); 
 
\t \t \t \t \t posting.done(function(data) { 
 
\t \t \t \t \t \t //alert(data); 
 
\t \t \t \t \t $("#muracietnov_id2").html(data); \t 
 
\t \t \t \t \t 
 
\t \t }); 
 
});
<tr> 
 
\t <div class="form-group" style="background-color:#f9f9f9;border:1px solid #ddd;border-radius:4px;padding:2px;"> 
 
\t \t <label>Müraciət Növü:</label><span style="color:#FF0000;">*</span></label> 
 
\t \t \t 
 
\t \t \t <select class="form-control" input-sm name="muracietnov" id="muracietnov_id" required>'; \t \t \t \t \t \t \t \t \t \t 
 
\t \t \t 
 
\t \t \t \t \t <OPTION VALUE="">Seçiminizi edin</OPTION>'; 
 
\t \t \t \t \t 
 
\t \t \t \t \t <OPTION VALUE="1">Su təchizatı</OPTION>'; 
 
\t \t \t \t \t <OPTION VALUE="2">Kanalizasiya</OPTION>'; 
 
\t \t \t \t \t </select>'; 
 
\t \t \t \t \t </div> 
 
</tr> 
 
\t \t \t 
 
\t \t \t 
 
<tr> 
 
\t <div class="form-group" style="background-color:#f9f9f9;border:1px solid #ddd;border-radius:4px;padding:2px;"> 
 
\t \t <label>Müraciət Səbəbi:</label><span style="color:#FF0000;">*</span></label> 
 
\t \t \t <select class="form-control" input-sm id="muracietnov_id2" required> 
 
\t \t \t </select> 
 
\t 
 
\t </div> 
 
</tr>

Verwandte Themen