yami007 Posted September 5, 2012 Share Posted September 5, 2012 I'm really not so good with ajax, I just need this IF condition to work. <script> $(document).ready(function() { $.ajax({ url: 'layouts/cities-list.php', data: 'debut', dataType: 'json', success: function(json) { $.each(json, function(index, value) { $('#country').append('<option value="'+ index +); if (index == 144) { $('#country').append(' selected="selected"'); } $('#country').append('>'+ value +'</option>'); }); } }); }); </script> Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/268046-if-problem-with-append-function/ Share on other sites More sharing options...
requinix Posted September 6, 2012 Share Posted September 6, 2012 Well you do have a syntax error in there: .append(' Link to comment https://forums.phpfreaks.com/topic/268046-if-problem-with-append-function/#findComment-1375628 Share on other sites More sharing options...
yami007 Posted September 6, 2012 Author Share Posted September 6, 2012 Yes there is an error, I forgot to do this: .append('<option value="'+ index +'"'); but that doesnt solve it. This is what it ouputs: <option select="" <="" value="1"></option> >Afghanistan <option select="" <="" value="193"></option> >Afrique du Sud <option select="" <="" value="2"></option> >Albanie <option select="" <="" value="3"></option> >Alg?rie <option select="" <="" value="81"></option> >Allemagne So there are still other errors. right? Link to comment https://forums.phpfreaks.com/topic/268046-if-problem-with-append-function/#findComment-1375668 Share on other sites More sharing options...
yami007 Posted September 6, 2012 Author Share Posted September 6, 2012 Thanks, alright I solved it! here is my new code: <script> $(document).ready(function() { var country_list; $.ajax({ url: 'layouts/cities-list.php', data: 'debut', dataType: 'json', success: function(json) { $.each(json, function(index, value) { country_list = '<option value="'+index+'"'; if ( index == 144 ) country_list += ' selected="selected"'; country_list += '>'+value+'</option>'; $('#country').append(country_list); }); } }); }); </script> Link to comment https://forums.phpfreaks.com/topic/268046-if-problem-with-append-function/#findComment-1375672 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.