I want the html to open when the password is right and I have tried .js, document.write, .html, href, div, document.getElementById and nothing is working when it's inside the if condition but I need it in there so it opens when the condition is right.
<script>
function 123()
{
var pass=document.getElementById("pass").value;
if(pass=="password")
{
alert("Logged In");
here is where the HTML code should go;
}
}
</script>
CodePudding user response:
You can create the html element in this page and give this element display none and when the password is correct change display example:
if(pass=="password") {
alert("Logged In");
document.getElementById("page").style.display="block";}
CodePudding user response:
You cant enter HTML code inside native JS code.
What you can do is to have HTML reference and change the HTML reference value with whatever you need.
<div id="myReferenceElem"></div>
<script>
function 123()
{
var pass=document.getElementById("pass").value;
if(pass=="password")
{
alert("Logged In");
document.getElementById("myReferenceElem").html = "<span>hi</span>"
}
}
</script>