\n \n \n \n Tutorials \n \n \n \n Lesson 1: Nature of Communication \n Lesson 2:\n Lesson 3:\n \n \n \n \n \n Home\n Highscores \n Support us!\n \n \n \n\n ","upvoteCount":0},{"@type":"Answer","text":"In html:\n\nPut class and id names between \" \"\n\nEj. ","upvoteCount":0},{"@type":"Answer","text":"diego Code Oh....","upvoteCount":0},{"@type":"Answer","text":"diego Code not working","upvoteCount":0},{"@type":"Answer","text":"diego Code Well, I put that id in another html file... That's why I've been wondering if having one js file for multiple html files is okay tbh","upvoteCount":0},{"@type":"Answer","text":"diego Code Since I only have one button working, I got curious a bit and removed the css from the link of the first html file. When I did that, the button completely stopped working. When I brought it back, it didn't work at all anymore.","upvoteCount":0},{"@type":"Answer","text":"Gordon Thank you for the information (⌒∇⌒) I'll not do that again...","upvoteCount":0}]} } CoursesCoursesCode CompilerCode CompilerDiscussPricingTeamsLog inRegisterMenu+ 1BUTTONS NOT WORKINGMy first button worked just fine but my second to last doesn't. I used document.getElementById("1stlesson").onclick = function () { location.href = "lessons.html"}; I made sure I put the id in the proper place same with the location. Also, I use the same javascript dile for multiple html files. Please help. This project in computer is due tomorrowhtmljavascriptid23rd Jan 2020, 11:39 AMBia Yumol25 AnswersSort by: VotesAnswer+ 7Can you put it in Code Playground and link it? Diagnosis is impossible without looking at your code.23rd Jan 2020, 11:51 AMFermi+ 5Bia Yumol Well, without the code, the only advice I can give is to start diagnosing from a minimal sample. https://code.sololearn.com/WaPImcARsJ49/?ref=app The code above clearly shows that both buttons are responsive. Try adding stuff according to what you have in your files until the buttons fail, then try to deduce what went wrong. That's how I usually debug my issues.23rd Jan 2020, 12:18 PMFermi+ 3You must separate JavaScript files for different html files. Otherwise the getElementById will return null and those onclick will raise Exceptions. (Which you should be able to see when you are in console of Developer's tool). Here are the steps: Install a proper IDE such as Visual Studio Code which will do the indentations for you. Restart your project with blank files, add the listeners one by one. Switch on Chrome Developer's Tool, read the console error message. To post code in Q&A, use code playground. https://www.sololearn.com/post/75089/?ref=app If you want to hyperlink to another page, use <a href=""> instead.23rd Jan 2020, 2:12 PMGordonM + 2Another one: Tags in html must be "nested" I.e. good: <div> <p>one </p> </div> BAD: <div> <p>one </div> </p> Clean up your html... i.e. here <header> <body> <div class="topbar"> <center> <p>Tutorials</p> </center> </header> </div> you are closing header before closing div... and body should be opened first...23rd Jan 2020, 2:00 PMunChabon+ 1Fermi. Problem still persists. However, this is what the Javascript looks like document.getElementById("tut").onclick = function () { location.href = "tutorial.html"}; document.getElementById("tutor").onclick = function () { location.href = "tutorial.html"}; document.getElementById("1stlesson").onclick = function () { location.href = "lessons.html"}; document.getElementById("back").onclick = function () { location.href = "HP.html"}; document.getElementById("tut").onclick = function () { location.href = "tutorial.html"}; document.getElementById("startgame").onclick = function () { location.href = "quiz.html"};23rd Jan 2020, 12:33 PMBia Yumol+ 1diego Code I'll try that.....23rd Jan 2020, 12:41 PMBia Yumol+ 1No... Of course... :) Look carefuly... If you have document.getElementById("back").onclick = function () { location.href = "HP.html"}; You must have an element with id="back" A lot of ids are missing in html..23rd Jan 2020, 1:43 PMunChabon+ 1Hi25th Jan 2020, 7:30 AMSadam Hussain0IDK if I can do that considering it's in multiple html files but one js file. Sorry I'm new to this23rd Jan 2020, 12:03 PMBia Yumol0Is your buttons' onclick listeners inside a window.onload = function() { } block? See https://code.sololearn.com/WAZeY9WKb4ZJ/#html23rd Jan 2020, 12:33 PMunChabon0Bia Yumol after every location.href("...."); Put } to close function() {23rd Jan 2020, 12:49 PMunChabon0diego Code Still won't work23rd Jan 2020, 12:56 PMBia Yumol0document.getElementById("tut").onclick = function () { location.href = "tutorial.html"}; document.getElementById("tutor").onclick = function () { location.href = "tutorial.html"}; document.getElementById("1stlesson").onclick = function () { location.href = "lessons.html"}; document.getElementById("back").onclick = function () { location.href = "HP.html"}; document.getElementById("tut").onclick = function () { location.href = "tutorial.html"}; document.getElementById("startgame").onclick = function () { location.href = "quiz.html"};23rd Jan 2020, 12:59 PMBia Yumol0<!DOCTYPE html> <html> <head> <title> MaxFluency Tutorials Page</title> <meta name="viewport" content="width-device-width"> <link rel="stylesheet" href="tutorial.css"> <script type="text/Javascript" src="hp.js"> </script> </head> <header> <body> <div class="topbar"><center> <p> Tutorials</p> </center> </header> </div> <div class="lessons"> <center> <button class=les id=1stlesson> <h3> Lesson 1: </h3> Nature of Communication </button> <button class=les id="2nd"> <h3>Lesson 2:</h3></button> <button class="les" id="3rd"> <h3>Lesson 3:</h3></button> </center> </div> <div class="nav"> <center> <button class="loc"> Home</button> <button class="loc"> Highscores </button> <button class="loc"> Support us!</button> </center> </div> <script type="text/Javascript" src="hp.js"> </script>23rd Jan 2020, 12:59 PMBia Yumol0In html: Put class and id names between " " Ej. <button class="les" id="1stlesson">23rd Jan 2020, 1:32 PMunChabon0diego Code Oh....23rd Jan 2020, 1:33 PMBia Yumol0diego Code not working23rd Jan 2020, 1:34 PMBia Yumol0diego Code Well, I put that id in another html file... That's why I've been wondering if having one js file for multiple html files is okay tbh23rd Jan 2020, 1:46 PMBia Yumol0diego Code Since I only have one button working, I got curious a bit and removed the css from the link of the first html file. When I did that, the button completely stopped working. When I brought it back, it didn't work at all anymore.23rd Jan 2020, 2:11 PMBia Yumol0Gordon Thank you for the information (⌒∇⌒) I'll not do that again...23rd Jan 2020, 2:16 PMBia YumolAnswerOften have questions like this?Learn more efficiently, for free:Introduction to Python7.1M learnersIntroduction to Java4.7M learnersIntroduction to C1.5M learnersIntroduction to HTML7.5M learnersHot todayDoes anyone have the solution for this challenge? 2 VotesHow would you solve the part of the C# Intermediate code project that requires operator overloading? 0 VotesI am beginner,This is will be right code? 1 VotesKernel in Jupyter 2 VotesSolved# Survey data format in coding for data 1 VotesWhy is it so hard to get a job as a junior dev? Or just wanting to do an internship. 1 VotesHow many days will It takes to completely learn front end 4 VotesSQL 2 VotesSolution to solving this bugged problem 2 VotesJAVA PROGRAMMING 1 Votes
Tutorials
My first button worked just fine but my second to last doesn't. I used document.getElementById("1stlesson").onclick = function () { location.href = "lessons.html"}; I made sure I put the id in the proper place same with the location. Also, I use the same javascript dile for multiple html files. Please help. This project in computer is due tomorrow
Learn more efficiently, for free:
Introduction to Python
7.1M learners
Introduction to Java
4.7M learners
Introduction to C
1.5M learners
Introduction to HTML
7.5M learners