It is necessary to copy the value from input name=[id] and name=[ssid] to form id ="addEntForm" to the same form id ="addEntForm" only in div id="div2"

Tried an attempt to fail

 var x = $('#addEntForm input[name="id"]').val() $('#div2 input[name="id"]').val(x); var x = $('#addEntForm input[name="ssid"]').val() $('#div2 input[name="ssid"]').val(x); 
 <form method="post" id="addEntForm" style="margin:0px" name="addform" enctype="multipart/form-data" onsubmit="openery();return false;"> <div id="div2"> <input name="id" value=""> // вставить сюда <input name="a" value="14"> <input name="ssid" value=""> // вставить сюда <input id="numi" value="1"> </div> </form> <form method="post" id="addEntForm" style="margin:0px" name="addform" enctype="multipart/form-data" onsubmit="openery();return false;"> <div> kjhkjh </div> <input name="id" value="55"> \\берем отсюда <input name="a" value="14"> <input name="ssid" value="W4sdENxN"> \\берем отсюда <input id="numi" value="1"> </form> 

  • found a temporary solution changed the id of the first form - Alexander Kotin
  • 2
    id should be unique on the page - Grundy
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

An ID cannot match any other ID in the same DOM space. Errors, usually, browsers do not throw, but the behavior will be different and certainly wrong (or accidentally correct, at the level of 'finger to the sky').

 function $(s){return document.querySelector(s);} // Syntactic sugar document.addEventListener('DOMContentLoaded', e => { // After loading the page, copy the value $('#to input[name="ssid"]').value = $('#from input[name="ssid"]').value; // Copy the 'ssid' value $('#to input[name="id"]').value = $('#from input[name="id"]').value; // Copy the 'id' value }); 
 <form method="post" id="to" style="margin:0px" name="addform" enctype="multipart/form-data" onsubmit="openery();return false;"> <div id="div2"> <input name="id" value=""><!-- вставить сюда --> <input name="a" value="14"> <input name="ssid" value=""><!-- вставить сюда --> <input id="numi" value="1"> </div> </form> <form method="post" id="from" style="margin:0px" name="addform" enctype="multipart/form-data" onsubmit="openery();return false;"> <div> kjhkjh </div> <input name="id" value="55"><!-- берем отсюда --> <input name="a" value="14"> <input name="ssid" value="W4sdENxN"><!-- берем отсюда --> <input id="numi" value="1"> </form> 

  • The problem was that the form serves to add material to the site and it was impossible to change it, a little tricky came to get a simple solution, the form that is automatically generated placed in the div with a unique ID. and voila for a couple of hours, the brain’s llamania turned out to be not that narrow and probably probably. at least while looking for how it would come up with so much that I learned for myself. - Alexander Kotin