I am trying to run this type of code:
Javascript Code:
var a = new XMLHttpRequest();
a.open('GET', 'text.txt');
a.onreadystatechange = function() {
var a_text = a.responseText;
If (a_text == "text I have written."){
document.getElementById("elem").innerHTML= a_text;
function z() {
document.getElementById("elem2").setAttribute("class", "invisible");
};
} else {
alert("Sorry, Text doesn't match.");
};
};
function click() {
z();
//Some other codes
}
HTML Code:
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
<style type="text/css" media="all">
.invisible {
display: none;
}
</style>
</head>
<body>
<p id="elem"></p>
<p id="elem2">Click the button to make me invisible.</p>
<button onclick="click()">Click Me</button>
<script src="javascript.js" type="text/javascript"></script>
</body>
</html>
At the last I want that when I click on the button, function click()
runs and function z()
runs only if a_text
matches required text. But even if the text matches, the console shows that z()
is not defined.
Please include if you have any alternative code to do it easily.
Help me out please.
This is a part of my code where I need the help. Solving this part will let me complete my project.
Aucun commentaire:
Enregistrer un commentaire