I have three populated drop down list depends on text field. when i type some data in text field drop down list act on this text field. And if i do not type anything then three populated drop down list depend on each other accordingly.
My problem is::: If Else condition is not working properly.Only Else condition is working here.... But separately they are working fine.
My coding are in below:
$(document).ready(function(){
if ($('#station_name').val().length != 0)
{
$('#station_name').on('change',function(){
var textID = $(this).val();
if(textID){
$.ajax({
type:'POST',
url:'ajaxData.php',
data:'station_name='+textID+'&action=entry',
success:function(html){
$('#pref').html(html);
$('#line').html('<option value="">-- 鉄道線を選択 --</option>');
$('#station').html('<option value="">-- 駅を選択 --</option>');
}
});
}else{
$('#pref').html('<option value="">-- 最初に都道府県を選択 --</option>');
$('#line').html('<option value="">-- 鉄道線を選択 --</option>');
$('#station').html('<option value="">-- 駅を選択 --</option>');
}
});
$('#pref').on('change',function(){
var prefID = $(this).val();
var textID = $('#station_name').val();
if(prefID){
$.ajax({
type:'POST',
url:'ajaxData.php',
data:'pref_cd='+prefID+'&action=e_line&station_name='+textID,
success:function(html){
$('#line').html(html);
$('#station').html('<option value="">-- 駅を選択 --</option>');
}
});
}else{
$('#line').html('<option value="">-- 鉄道線を選択 --</option>');
$('#station').html('<option value="">-- 駅を選択 --</option>');
}
});
$('#line').on('change',function(){
var lineID = $(this).val();
var prefID = $('#pref').val();
var textID = $('#station_name').val();
if(lineID){
$.ajax({
type:'POST',
url:'ajaxData.php',
data:'line_cd='+lineID+'&action=e_station&pref_cd='+prefID+'&station_name='+textID,
success:function(html){
$('#station').html(html);
}
});
}else{
$('#station').html('<option value="">-- 駅を選択 --</option>');
}
});
}
else
{
$('#pref').on('change',function(){
var prefID = $(this).val();
if(prefID){
$.ajax({
type:'POST',
url:'ajaxData.php',
data:'pref_cd='+prefID+'&action=line',
success:function(html){
$('#line').html(html);
$('#station').html('<option value="">-- 駅を選択 --</option>');
}
});
}else{
$('#line').html('<option value="">-- 鉄道線を選択 --</option>');
$('#station').html('<option value="">-- 駅を選択 --</option>');
}
});
$('#line').on('change',function(){
var lineID = $(this).val();
var prefID = $('#pref').val();
if(lineID){
$.ajax({
type:'POST',
url:'ajaxData.php',
data:'line_cd='+lineID+'&action=station&pref_cd='+prefID,
success:function(html){
$('#station').html(html);
}
});
}else{
$('#station').html('<option value="">-- 駅を選択 --</option>');
}
});
}
$('#btn_eki').click(function(){
var $option = $('#station option:selected');
var station = $option.val();
window.parent.add_tag(station, "", $('#wishtxt').html(),1);
window.parent.$('#nearStForm' + $('input[name="wish"]').val()).slideUp();
return false;
});
$('#wishtxt').html($('#form_eki [name="wish"]').val());
});
Aucun commentaire:
Enregistrer un commentaire