Tell me how to implement this with

<form><select><option></option></select></form> 

 <form> <input id="btn1" type="button" value="File1"> <input id="btn2" type="button" value="File2"> <input id="btn3" type="button" value="File3"> <input id="btn4" type="button" value="File4"> </form> <script> $(document).ready(function(){ $('#btn1').click(function(){ $.ajax({ url: "File1.php", cache: false, success: function(html){ $("#container").html(html); } }); }); $('#btn2').click(function(){ $.ajax({ url: "File2.php", cache: false, success: function(html){ $("#container").html(html); } }); }); $('#btn3').click(function(){ $.ajax({ url: "File3.php", cache: false, success: function(html){ $("#container").html(html); } }); }); $('#btn4').click(function(){ $.ajax({ url: "File4.php", cache: false, success: function(html){ $("#container").html(html); } }); }); }); </script> 

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky ♦

1 answer 1

Probably like this:

 $('select').on('change', function() {//ΡΠ»ΡƒΡˆΠ°Π΅ΠΌ, ΠΊΠΎΠ³Π΄Π° измСнится Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ сСлСкта fileGet($(this).val());//ΠΏΡ€ΠΈ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠΈ Π²Ρ‹Π·Ρ‹Π²Π°Π΅ΠΌ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΡŽ, с Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΌ(Π²Ρ‹Π±Ρ€Π°Π½Π½Ρ‹ΠΌ) Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ΠΌ сСлСкта }); function fileGet(file) {//собссно Ρ‚ΠΎΡ‚ ΠΆΠ΅ ΠΊΠΎΠ΄, ΠΎΠ±Π΅Ρ€Π½ΡƒΡ‚Ρ‹ΠΉ Π² Ρ„ΡƒΠ½ΠΊΡ†ΠΈΡŽ file = file + ".php"; console.log(file); $.ajax({ url: file, cache: false, success: function(html) { $("#container").html(html); } }); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form> <select> <option value='File1'>File1</option> <option value='File2'>File2</option> <option value='File3'>File3</option> </select> </form> 

  • Thank! It does not work, I can not understand ... - Andrew
  • @ Andrei mb because your file name with a capital began, I have a lowercase. Now changed, try this - SLy_huh
  • Everything in the files is correct, I have a lowercase. Only does not load the content. - Andrei
  • @Andrey, I changed the code a bit, see what will be spamming to the console. If the names in the console match the file names, the problem is in the request, but it was taken from your example - SLy_huh
  • Uncaught TypeError: $ (...). On is not a function - Andrew