Jquery chained select box, how to disable blank option -
<select id="countryselect" name="country> <option value="us">united states</option> . . </select> <select id="cityselect" name="city"></select>
this html code and
$.cityselect = function(){ var td= $('#countryselect').val(); $.ajax({ type: "post", url: "action.php", data: {'countrytd':td}, success: function(e){ $('#cityselect').html(e); }, }); };
this chained select function. mysql process creating options in action.php.
here thing, when use function, result that
<select id="cityselect" name="city"> <option value></option> // empty value <option value="1">new york</option> <option value="2">broadway</option> </select>
i dont want empty value because need information. there no empty value wrote anywhere. there no problem in php file because when changed this
$('#cityselect').html(e);
to this
$('#cityselect').html('<option value="1">name</option>');
it adds blank value top anyway.
how can disable process or how can remove blank value after operation.
also when use 'e' comes success includes metatags , other head elements use language character set in action.php . how can clean these?
as @roasted stated, difficult figure out without code, should resolve @ least part of issue you:
first, note: of jquery 1.8 success
callback method deprecated:
the jqxhr.success(), jqxhr.error(), , jqxhr.complete() callbacks deprecated of jquery 1.8. prepare code eventual removal, use jqxhr.done(), jqxhr.fail(), , jqxhr.always() instead.
here solution of problem. not solution of it, as, if getting blank value sql query, there problem query, database, or both. however, provide 'solution' front-end part of problem -> (this predicated on assumption php file builds relevant <option>
elements <select>
element):
$.cityselect = function(){ var td= $('#countryselect').val(); $.ajax({ type: "post", url: "action.php", data: {'countrytd':td}, }).done(function(data){ // better not use 'e' variable (can confusing) if($(data).html().replace(/\s/g,'').length){ //there number of ways check //(depends on expecting). // example used catch blank spaces $('#cityselect').html(data); } }) };
Comments
Post a Comment