2016-05-25 7 views
0

PHPとJSのファイルが1つあります。このファイルには3つのドロップダウンがあり、カスケードを適用しようとしましたが、機能しません。最初のドロップダウンでオプションを選択すると、2番目のドロップダウンには値がありません。JSを使用してカスケードドロップダウンが機能しない

これを修正するにはどうすればよいですか?ドロップダウンのための

PHP:

<form action='' method='post' name='resumeDatabank' id='resumeDatabank'> 
<div class="div-select"> 
<label for="list_position" id="#ddress_search LABEL">Position</label> 
<br/> 
<select name="list_position" id="filterbyposition"> 
    <option name="default" class="filter_by" selected="selected" value="Select by Position">Select by Position</option> 
    <?php 
    foreach($query_position as $option){ 
     if(isset($_POST['list_position']) && $_POST['list_position'] == $option->position) 
      echo '<option name="list_position" class="filter_by" selected value="'. $option->position .'">'. $option->position .'</option>'; 
     else 
     echo '<option name="list_position" class="filter_by" value="'. $option->position .'">'. $option->position .'</option>'; 
    }; 
    ?> 
</select> 
</div> 
<div class="div-select"> 
<label for="list_location" id="#ddress_search LABEL">Location</label> 
<br/> 
<select name="list_location" id="filterbylocation"> 
    <option name="default" class="filter_by" selected="selected" value="Select by Location">Select by Location</option> 
    <?php 
    foreach($query_locations as $option){ 
     if(isset($_POST['list_location']) && $_POST['list_location'] == $option->hiring_location) 
      echo '<option name="list_location" class="filter_by" selected value="'. $option->hiring_location .'">'. $option->hiring_location .'</option>'; 
     else 
     echo '<option name="list_location" class="filter_by" value="'. $option->hiring_location.'">'. $option->hiring_location .'</option>'; 
    }; 
    ?> 
</select> 
</div> 
<div class="div-select"> 
<label for="list_processed" id="#ddress_search LABEL">Processed</label> 
<br/> 
<select name="list_processed" id="filterbyprocessed"> 
    <option name="default" class="filter_by" selected="selected" value="Select by Processed">Select by Processed</option> 
    <?php 
    foreach($query_processed as $option){ 
     if(isset($_POST['list_processed']) && $_POST['list_processed'] == $option->processed_option) 
      echo '<option name="list_processed" class="filter_by" selected value="'. $option->processed_option .'">'. $option->processed_option .'</option>'; 
     else 
     echo '<option name="list_processed" class="filter_by" value="'. $option->processed_option.'">'. $option->processed_option .'</option>'; 
    }; 
    ?> 
</select> 
</div> 
<div class="div-input"> 
<input type="submit" value="Search" class="div-input-submit"/> 
</div> 
</form> 

JS:

jQuery("#filterbyposition").live('change',function() { 
    var selectVal = jQuery('#filterbyposition :selected').val(); 
    alert(selectVal); 
    var $output = jQuery('#filterbylocation').html(''); 

    jQuery.ajax({ 
     url: 'page-resume-databank.php', 
     data: "n="+selectVal, 
     dataType: 'json', 
     success: function(data){ 
      jQuery.each(data, function(key,value){ 
       $output.append("<option value='"+value.id+"'>"+value.filterbylocation+"</option>"); 
      }); 
     } 
    }); 
}); 

答えて

0

あなたのコードは、コードのjQuery( '#のfilterbylocation')、あなたがfilterbypositionのためのイベントを追加

jQuery("#filterbyposition").live('change',function() { 
    var selectVal = jQuery('#filterbyposition :selected').val(); 
    alert(selectVal); 
    *var $output = jQuery('#filterbylocation').html('');* 

間違っています.html( '')は2番目のドロップダウンが設定されていますが、値はありません。 jQueryのへ

変更して(「#のfilterbyposition」)で。HTML(「」)

+0

下回るAjaxの後.each関数の必要はありません:// localhostの/テスト/再開-2/page-resume-databank.php?n = sales%20associate 404(見つかりません) – User014019

+1

申し訳ありませんが、あなたのlocalhostにアクセスできません。 – Iamdeveloper

+0

何が間違っています、なぜページが見つからないのですか? 1つのファイルに保存されているjsとphpだけが – User014019

0

ページレジューム-databank.phpエコー選択形式で出力して、AJAXでの応答は、ちょうど第二降下を追加ダウン。私はこのhttpで、エラーを持っている

AJAXリクエスト

var strURL="findStateing.php?platform="+xx; 
var req = getXMLHTTP(); 
if (req) { 
    req.onreadystatechange = function() { 
     if (req.readyState == 4) { 
     // only if "OK" 
     if (req.status == 200) {      
     document.getElementById('statediv').innerHTML=req.responseText; 
     } else { 
     alert("Problem while using XMLHTTP:\n" + req.statusText); 
    } 
}    
}   
req.open("GET", strURL, true); 
req.send(null); 
} 

findStateing.php responeエコーとして

$xx=$_GET['platform']; 
    <select name="amount" id="amount" class="form-control" required> 
     <?php $query=mysql_query("SELECT * FROM table WHERE xx='$xx'"); 
      while($result=mysql_fetch_array($query)){ ?> 
      <option value="<?php echo $result['pv'];?>"><?php echo $result['pv'];?> PV &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php if(strlen($result['pv']) < 4) { echo "&nbsp;&nbsp;"; }?>MYR <?php echo $result['rm'];?></option> 
     <?php } ?> 
    </select> 
+0

どのように? – User014019

+0

JSとPHPとhtmlフォームが1つのファイルに含まれているとすれば、私は実際の例を教えてください。どのようにajaxでそれを呼び出すには? – User014019

+0

chage jqueryまたは任意の関数を使用して、その中にajaxコードを追加し、それを表示するために2番目の選択フィールドIDを与えます – krishna

関連する問題