my node code:
app.get('/block_name', function (req,res){
var sql='SELECT `block_name`,`block_id` FROM `tbl_block` ';
connection.query(sql,function(err, result) {
if (err) throw err;
res.json(result);
});
});
app.get('/site_name', function (req,res){
var sql='SELECT `site_name`,`site_id` FROM `tbl_site` ';
connection.query(sql,function(err, result) {
if (err) throw err;
res.json(result);
});
});
HTML
Site
<select name="site" id="dropdown" >
<option value="">- select -</option>
</select>
<label class="field" >Block</label>
<select name="block" id="dropdown1" >
<option value="">- select -</option>
</select>
SCRIPT
<script>
$(document).ready(function(){
$.ajax({
url : "/site_name",
type : "GET",
success : function(data){
var len = data.length;
console.log(data);
$("#dropdown").empty();
for(var i =0; i<len;i++){
var value1 = data[i]['site_name'];
var value2 = data[i]['site_id'];
$("#dropdown").append("<option value='"+value2+"' >"+value1+"</option>");
}
}
});
});
$(document).ready(function(){
$.ajax({
url : "/block_name",
type : "GET",
success : function(data){
var len = data.length;
console.log(data);
$("#dropdown1").empty();
for(var i =0; i<len;i++){
var value1 = data[i]['block_name'];
var value2 = data[i]['block_id'];
$("#dropdown1").append("<option value='"+value2+"' >"+value1+"</option>");
}
}
});
});
</script>
my second dropdown lists all the data but i need particular thing to be listed according to the first dropdown.
Thanks in advance..
Sorry for my bad English
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…