0

I am an intermediate HTML and I am starting to learn JavaScript within it.

<html> <head> <title>Uh oh! No page.</title> <h1 class="index">The page you requested for is not available! Click <a href="index.html" class="index">here</a> to go back</h1> <style> .index { text-decoration: none; font-family: Arial; } </style> </head> <body onload="myfunc()"> <script> function myfunc() { var x; if (confirm("Im confuzzled! Where did the page go?\n\nSelect OK to be redirected and Cancel to do it manually ") == true) { window.location = "index.html"; } else { alert("You will now manually have to redirect to the lemoon homepage"); } document.getElementById("demo").innerHTML = x; } </script> </body> <footer onload="pageLocate()"> <script> function pageLocate() { document.getElementById("demo").innerHTML = "Page location is: " + window.location.href; } </script> </footer> </html>
I cannot get the document tag to display anything. Can you please help?

4
  • 3
    Where is the element with id "demo"? Commented Dec 14, 2016 at 0:34
  • 1
    You're using getElementById to look for an element named 'demo" however, you don't have anything in your HTML by that tag id name. Might be helpful to look in web inspector's console to get a reading of Javascript's errors. Commented Dec 14, 2016 at 0:34
  • 2
    Also that <h1> probably shouldn't be in the <head>. Commented Dec 14, 2016 at 0:35
  • 3
    Why do you have more HTML and scripts AFTER the close of the body tag. Correct all your HTML before worrying about JavaScript. Commented Dec 14, 2016 at 0:35

3 Answers 3

1

i have scanned your code twice and still can't see where is the tag that has id = "demo". If you don't create a tag with an id, which is in this case : "demo", then when you call for it, how can console even work when it can't find the target ? i believe that this is your fault

Sign up to request clarification or add additional context in comments.

2 Comments

oh, and something else, i believe that it will be more clear if you create a var that contains the string then pass it into "confirm" rather than writing the whole string in it
Uh, since i can't comment so i have to do this
0

There is no element with the ID of "demo". You would need to give the element that you want to perform a function with an id of "demo" for this to work.

EX:

<div id="demo">Hello!</div> 

You did not have to ask this question, it just would have taken a little bit of thinking or some searching on google.

2 Comments

That's the exact same answer that was already given 5 minutes ago. What does your answer add that hasn't already been said?
Oh, i didn't see that answer, it just took me time to get this one down because I programming on rainbowhover.ml
0

I really hope you wanted something like this, as there were some not so logical things there.

1.footer and h1 tags belong to the body of the page (inside tag). 2.you pretty much created a function to get some data for another function, that can be accessed from the other function

<html> <head> <title>Uh oh! No page.</title> <style> .index { text-decoration: none; font-family: Arial; } </style> <script> function myfunc() { if (confirm("Im confuzzled! Where did the page go?\n\nSelect OK to be redirected and Cancel to do it manually ") == true) { window.location = "index.html"; } else { alert("You will now manually have to redirect to the lemoon homepage"); } document.getElementById("demo").innerHTML = "Page location is: " + window.location.href; } </script> </head> <body onload="myfunc()"> <h1 class="index">The page you requested for is not available! Click <a href="index.html" class="index">here</a> to go back</h1> <footer id="demo" onload="pageLocate()"> </footer> </body> </html>

1 Comment

Thanks! Sorry that I made so many careless mistakes. I am still learning javascript

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.