When I click on the cancel button, I hide the Edit div and then show the Info div. The first condition works:

function main() { var info = document.getElementById("Info"); var edit = document.getElementById("Edit"); var edit_button = document.getElementById("Edit_button"); if (getComputedStyle(info).display == "none" && getComputedStyle(edit).display == "block") { edit.style.display = "none"; info.style.display = "block"; edit_button.style.display = "block"; alert("INFO" + info.style.display + " Edit" + edit.style.display + "Edit_Button" + edit_button.style.display); } if (getComputedStyle(edit).display == "none" && getComputedStyle(info).display == "block") { info.style.display = "none"; edit_button.style.display = "none"; edit.style.display = "block"; } } 
 #Info { display: block; } #Edit { display: none; } #Edit_button { display: block; } 
 <div id="Info"> .... </div> <input type="button" value="Edit" id="Edit_button" onclick="main()"> <div id="Edit"> <form name="Edit_form" method="POST" onsubmit=""> ... <input type="button" value="Cancel" onclick="main()" class="Button"> </div> 

That alert displays - enter image description here

BUT! The edit div remains (must hide), and the info div does not appear.

  • Well, wow, what technology ... This is edited! Thank you! - Sckoriy
  • After the first condition, the second condition obviously works, in which edit is shown and info - andreymal is hidden pm
  • @andreymal How can it work if I don’t click on edit_button to complete it? I don’t understand anything, sorry) - Sckoriy pm
  • one
    And what difference does it make if you press the same main() when you press any button? Naturally, both conditions are checked on both buttons in order from top to bottom. In the first condition, you do edit.style.display = "none" and info.style.display = "block" , after which the second condition is checked further down the code - and according to previous changes, it turns out to be true. In your code there is nothing between the first and the second condition that would prevent the second condition from working - andreymal
  • @andreymal wow .. I didn’t think about it) That's it, added a return for each condition. - Sckoriy 6:55 pm

0