2016-12-29 5 views
0

ここは自分のコードです。ComboBoxで選択した値を取得し、2番目のComboBoxクエリに使用する方法

私はいくつかのコンボボックスを持っています。 ComboBoxでValueを選択し、別のクエリで値を使用する必要があります。私がオラクルから選択するすべてのデータ。

これは私の最初のComboBoxで、2番目のComboBoxのクエリでこのComboBoxのオプションのVALUEを使用する必要があります。私は2番目のコンボボックスが最初の選択に依存することを意味します。

私はどのように「価値」を得ることができますか?私はonchange="this.form.submit()"を使用しようとしましたが、ページを更新して選択を失います。たぶん私は新しいPHPファイルを作成し、 "js_post.php" という名前を付け

<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>

答えて

0

...アヤックスでそれを行うことが可能になります。私たちが最初のComboBoxから任意のオプションを選択したとき、javascriptは "js_post.php"に値を送信し、そこにコードは値を表示し、値を選択するオプションに依存します。

<?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 } 
 
?>

ここではJavascriptとHTMLは、私が使用していることです。

$("#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>

関連する問題