I'm new here and looking for some assistance, so please help if you can :)
I'm working on a web page but encountered an issue that I hope you can help me solve. Here are the 3 files involved:
- home.html --> Main page
- login.html --> Page with a form to be opened in an iframe within home.html
- hh.js --> JavaScript file
My goal is to display the user's name instead of "Login" on home.html after they press submit on the login.html page.
For now, I'm just trying to change the word "Login" to something else temporarily instead of using the actual username.
Here is the code from hh.js (JavaScript file):
function goback(){
alert("yes")
var str = document.getElementById("demo").innerHTML;
var res = str.replace("Login","ppap");
document.getElementById("demo").innerHTML = res;
}
Below is the code snippet from home.html where the word "Login" appears:
<a onclick="login()"><span id="demo">Login</span></a>
And here is the full code from login.html:
<html>
<head>
<script language="javascript" src="hh.js">
</script>
</head>
<body bgcolor="#000033">
<br><font color="white">
LOGIN<br>
USERNAME:<input type="text" id="user"><br>
PASSWORD:<input type="password"><br>
<button onclick="goback()">Submit</button>
</body></font>
</html>
Issue-
I have the function goback() in both files just for testing purposes. Both pages have buttons (submit button on login.html && random button on home.html with the same function).
When I click the button on login (iframe in home.html), the alert pops up saying "yes" but doesn't change the "Login" text. However, when I click the button on home.html with the same function, the alert appears and the text changes to "ppap".
I think the problem is that the getElementById search is looking for the id in login.html instead of home.html.
If anyone can help me target getElementById to home.html, I would really appreciate it. Please provide a simplified code as my school teachers might not understand complex codes. Additionally, any other simple methods to achieve the same result quickly would also be helpful like hiding the area until the login function is called and then triggering the goback() function on the same page.