Note that there are some explanatory texts on larger screens.

plurals
  1. POEfficient jquery way to select item and place in textbox
    text
    copied!<p>I have a problem in implementing and efficient way by using JQuery to select and item from combobox and place it in textfield. See the image below the problem is when Firstly I select and element from combobox shown by 1 it places item properly in desired textfield shown by 2 but later when I select from second combobox the previous as well as current changes. Whole code as follows.</p> <pre><code> $("input[name^=pasta_text]").focus(function() { var gecerliid=$(this).parent().get(0).id; var mevcutdeger=$(this).val(); var sondeger=$(this).val(); var seciliGrup=""; if(typeof orjinal === "undefined") { var orjinal=$(this); } else { delete orjinal; var orjinal=$(this); } alert($("#pastatext["+gecerliid+"]").id()); if($.inArray(mevcutdeger,Knowledge)&gt;=0) { seciliGrup="Knowledge"; mevcutgrup=0; mevcutsira=$.inArray(mevcutdeger,Knowledge); } if($.inArray(mevcutdeger,Comprehension)&gt;=0) { seciliGrup="Comprehension"; mevcutgrup=1; mevcutsira=$.inArray(mevcutdeger,Comprehension); } if($.inArray(mevcutdeger,Application)&gt;=0) { seciliGrup="Application"; mevcutgrup=2; mevcutsira=$.inArray(mevcutdeger,Application); } if($.inArray(mevcutdeger,Analysis)&gt;=0) { seciliGrup="Analysis"; mevcutgrup=3; mevcutsira=$.inArray(mevcutdeger,Analysis); } if($.inArray(mevcutdeger,Synthesis)&gt;=0) { seciliGrup="Synthesis"; mevcutgrup=4; mevcutsira=$.inArray(mevcutdeger,Synthesis); } if($.inArray(mevcutdeger,Evaluation)&gt;=0) { seciliGrup="Evaluation"; mevcutgrup=5; mevcutsira=$.inArray(mevcutdeger,Evaluation); } //$("#pasta_div").text(seciliGrup).show(); $(this).hide(); $("#learn_outcome").attr("size","49"); $('input[name=pasta_submit], select[name=pasta_grup], select[name=pasta_fiil]').remove(); $(this).before("&lt;select name='pasta_grup' class='formin'&gt;"); //&lt;select name='pasta_grup[".($s+1)."]' class='formin'&gt;&lt;option value='-1'&gt;GRUP&lt;/option&gt;&lt;/select&gt;&lt;select name='pasta_fiil[".($s+1)."]' class='formin'&gt;&lt;option value='-1'&gt;FİİL&lt;/option&gt;&lt;/select&gt;&lt;input type='button' value='OK' class='formbutton' name='pasta_submit' id='pasta_submit'&gt; $.each(taxonomy, function(key, value) { $("select[name=pasta_grup]") .append($('&lt;option&gt;', { value : key }) .text(value)); }); $(this).before("&lt;/select&gt;"); $("select[name=pasta_grup]").val(mevcutgrup); $("select[name=pasta_fiil]").remove(); $(this).before("&lt;select name='pasta_fiil' class='formin'&gt;"); fiilOlustur(mevcutgrup); $("select[name=pasta_fiil]").val(mevcutsira).focus(); $(this).before("&lt;/select&gt;"); $(this).before("&lt;input type='button' value='OK' class='formbutton' name='pasta_submit'&gt;"); $("#pasta_div").text("mevcutdeger:"+mevcutdeger+" mevcutsira:"+mevcutsira+" mevcutgrup:"+mevcutgrup+" eleman:"+$(this).id); $("select[name=pasta_grup]").live("change",function() { mevcutgrup=$("select[name=pasta_grup] option:selected").val(); $('select[name=pasta_fiil]').empty(); fiilOlustur(mevcutgrup); $('select[name=pasta_fiil] option:first').attr("selected","selected"); }); $("select[name=pasta_fiil]").live("change",function() { sondeger=$("select[name=pasta_fiil] option:selected").text(); orjinal.val(sondeger); $("#pasta_div").text("post change: "+sondeger); }); $("input[name=pasta_submit]").live("click", function() { orjinal.show().empty(); sondeger = $("select[name=pasta_fiil] option:selected").text(); $("#pasta_div").text("post click: "+sondeger); orjinal.addClass("forminred").blur(function() { $(this).show(); }); $('input[name=pasta_submit], select[name=pasta_grup], select[name=pasta_fiil]').remove(); }); $("#pasta_div").text("last level: "+sondeger); //$("#pasta_div").text("sondeger: "+sondeger+" sonra: "+$(this).val()); $(this).val(sondeger).addClass("forminred").blur(function() { $(this).show(); }); function fiilOlustur(grupno) { if(grupno==0) { $.each(Knowledge, function(key, value) { $('select[name=pasta_fiil]').append($('&lt;option&gt;', { value : key }).text(value)); }); } if(grupno==1) { $.each(Comprehension, function(key, value) { $('select[name=pasta_fiil]').append($('&lt;option&gt;', { value : key }).text(value)); }); } if(grupno==2) { $.each(Application, function(key, value) { $('select[name=pasta_fiil]').append($('&lt;option&gt;', { value : key }).text(value)); }); } if(grupno==3) { $.each(Analysis, function(key, value) { $('select[name=pasta_fiil]').append($('&lt;option&gt;', { value : key }).text(value)); }); } if(grupno==4) { $.each(Synthesis, function(key, value) { $('select[name=pasta_fiil]').append($('&lt;option&gt;', { value : key }).text(value)); }); } if(grupno==5) { $.each(Evaluation, function(key, value) { $('select[name=pasta_fiil]').append($('&lt;option&gt;', { value : key }).text(value)); }); } } /*if(seciliGrup&lt;&gt;"") { fiilFonksiyon(); }*/ /*var mevcutdeger=$(this).index(); $("#pasta_div").text(mevcutdeger).show(); grupFonksiyon();*/ }); </code></pre> <p>Could you guide me how to implement it in more efficient way by using JQuery ? Is there any other way that you know that can solve my issue ? Thank you.</p> <p><img src="https://i.stack.imgur.com/OaKUg.jpg" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload