Good day! Here's a problem I have such a div for example

<div> <form action='update_user.php' method='post' enctype='multipart/form-data'> Π˜Π·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Π°Π²Π°Ρ‚Π°Ρ€:<br> Π˜Π·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ Π΄ΠΎΠ»ΠΆΠ½ΠΎ Π±Ρ‹Ρ‚ΡŒ Ρ„ΠΎΡ€ΠΌΠ°Ρ‚Π° jpg, gif ΠΈΠ»ΠΈ png. <br> <input type="FILE" name="fupload"> <input type='submit' name='submit' value='ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ'> </form> </div> 

and there are two links to launch functions like this

  <div class="classnewsbg"> <a href="javascript:Swapsettings('osnov')">ΠžΡΠ½ΠΎΠ²Π½Ρ‹Π΅ настройки</a> </div> <div class="classnewsbg"> <a href="javascript:Swapsettings('personal')">ΠŸΠ΅Ρ€ΡΠΎΠ½Π°Π»ΡŒΠ½Ρ‹Π΅ настройки</a> </div> 

the essence of the task is that the content of the Diva with the form when you click on a link changes to another, say, another

I tried it like this

 <script src="javascript/jquery-1.10.2.min.js" type="text/javascript"></script> <script type="text/javascript"> function Swapsettings(swapto) { if (swapto == 'osnov') { $(".settings").replaceWith("<div class='settings'><?php require_once('phpscripts/ossettings.php');?></div>"); } else if (swapto == 'personal') { $(".settings").replaceWith("<div class='settings'>Π’ΡƒΡ‚ Ρ…Ρ‚ΠΌΠ» ΠΊΠΎΠ΄ с Ρ„ΠΎΡ€ΠΌΠΎΠΉ </div>"); } } </script> 

But neither the insertion of the finished code into the function nor the insertion of the code from the file helps. Tell me how best to do?

  • one
    You have not registered class diva with the form. Although in this situation it would be better to use id. - fori1ton
  • four
    Then the question is, do not give a jQuery to you if you are looking for elements using getElementById? - dekameron

2 answers 2

As one of the options.

 window.onload = function() { document.getElementById('divForm').innerHTML = document.getElementById('kod1').innerText; } function Swapsettings(swapto) { if (swapto == 'osnov') { document.getElementById('divForm').innerHTML = document.getElementById('kod1').innerText; } else { document.getElementById('divForm').innerHTML = document.getElementById('kod2').innerText; } } 
 <div id="divForm"></div> <br> <div class="classnewsbg"> <a href="javascript:Swapsettings('osnov');">ΠžΡΠ½ΠΎΠ²Π½Ρ‹Π΅ настройки</a> </div> <div class="classnewsbg"> <a href="javascript:Swapsettings('personal');">ΠŸΠ΅Ρ€ΡΠΎΠ½Π°Π»ΡŒΠ½Ρ‹Π΅ настройки</a> </div> <div style="display: none;"> <textarea id="kod1"><form action='update_user.php' method='post' enctype='multipart/form-data'> Π˜Π·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Π°Π²Π°Ρ‚Π°Ρ€:<br> Π˜Π·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ Π΄ΠΎΠ»ΠΆΠ½ΠΎ Π±Ρ‹Ρ‚ΡŒ Ρ„ΠΎΡ€ΠΌΠ°Ρ‚Π° jpg, gif ΠΈΠ»ΠΈ png. <br> <input type="FILE" name="fupload"> <input type='submit' name='submit' value='ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ'> </form></textarea> <textarea id="kod2"><form action='update_foto.php' method='post' enctype='multipart/form-data'> Π˜Π·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Ρ„ΠΎΡ‚ΠΎΠ³Ρ€Π°Ρ„ΠΈΡŽ:<br> Π˜Π·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ Π΄ΠΎΠ»ΠΆΠ½ΠΎ Π±Ρ‹Ρ‚ΡŒ Ρ„ΠΎΡ€ΠΌΠ°Ρ‚Π° jpg, gif ΠΈΠ»ΠΈ png. <br> <input type="FILE" name="fupload"> <input type='submit' name='submit' value='ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ'> </form></textarea> </div> 

    And thanks decided differently already - through getelement by id display none / block