how to determine drop down is loaded(by AJAX) an selected in jquery -


i have page 2 select boxes, 1 of loaded ajax call. want validate elements jquery/javascript before enable submit button. jquery works fine when change static select (strdirectorate) unable value of dropdown loaded ajax call.

i need check whether people have select item rather first one(first item have blank value) in second drop down.

i have used jquery 1.7.2 //my first dropdown works 100% accurate

//load sub category category $(document).ready(function() {   $("#category_id").live('change', function() {     $("#span_sub_category").html( '<img src="<?php echo $base_client;?>images/ajax-loader.gif"/>' );     $.ajax({         type: 'post',         cache: false,         url: '<?php echo $base_client;?>ajax-response.php',         data: 'category_id='+$('#category_id').val()+'&drop_down_name=sub_category_id&operation=load_sub_category',         success: function(data) {             if(data){                 var obj = jquery.parsejson(data);                 if(obj.response==1){                     //$('#msg_speaker_login').hide();                     $('#span_sub_category').hide().html(obj.message).slidedown(1000);                 }else{                     $('#span_sub_category').hide().html(obj.dd_list).slidedown(1000);                     table_name="directory_company";                     prepare_sorting_list();                 }             }else{                 //json unable return data.             }         }     });   }); }); 

here dropdown loaded ajax call.

<select name="sub_category_id" id="sub_category_id">   <option value="">sub category</option>   <option value="2">mobile engineers</option>   <option value="1">motor engineersx</option>   <option value="3">chemical engineers</option> </select> 

now in submit button click event try check whether sub_category_id loaded , selected non blank value.

$(document).ready(function() {   $('#btnkeywordsaveupdate').live('click', function() {      if(typeof("sub_category_id") != "undefined")        alert("sub category not loaded");      else if($('#sub_category_id').val()=="")        alert("please select sub category");      alert(msg);   }); }); 

finally, problem is: alert("sub category not loaded"); sub category drop down loaded page , have select non blank value. so, how check whether sub category drop down loaded page , selected or not.

try changing if(typeof("sub_category_id") != "undefined") if(typeof("sub_category_id") == "undefined") or remove altogether. if(typeof("sub_category_id") != "undefined") going return string anyway

change code to

$(document).ready(function() {   $('#btnkeywordsaveupdate').live('click', function() {      if($('#sub_category_id').length == 0)        alert("sub category not loaded");      else if($('#sub_category_id').val()=="")        alert("please select sub category");      alert(msg);   }); }); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -