Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,194,665 members, 7,955,401 topics. Date: Sunday, 22 September 2024 at 03:44 AM |
Nairaland Forum / Science/Technology / Programming / Please Help A Script Kiddie Out With Javascript (1382 Views)
My Semester GPA Calculator With Javascript / Help A Beginner With Javascript / How Do I Create Responsive Slider With Javascript (2) (3) (4)
Please Help A Script Kiddie Out With Javascript by donlyone(m): 10:53am On May 31, 2016 |
Please gurus in the house, I am stuck and I need your help with JavaScript. I am trying to apply JavaScript to a page on PC, but whenever I call a function, only the first function works. The other ones don't work. I have to remove other functions before a particular function will work. Even when I am using only one function, and I call the same function a second time to use it on another element, it doesn't work. What am I doing wrong? Parts of the code posted below: var monthsY = ["Jan", "Feb", "Mar", "Apr", "May", "June", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"]; function greeT(){ switch(new Date().getHours()){ case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: greet = "Good morning"; break; case 12: case 13: case 14: case 15: case 16: greet = "Good afternoon"; break; case 17: case 18: case 19: case 20: case 21: case 22: case 23: greet = "Good evening" break; } return greet; } function salut(y){ document.getElementById(y).innerHTML=greeT(); } salut("salut" var mo = function(x){ s=document.getElementById(x); s.style.backgroundColor="green"; s.style.color="black"; s.style.fontSize="35px"; } mo("mo" |
Re: Please Help A Script Kiddie Out With Javascript by Nobody: 11:05am On May 31, 2016 |
Try adding comments to your codes so another can know what you are trying to do. |
Re: Please Help A Script Kiddie Out With Javascript by donlyone(m): 12:49pm On May 31, 2016 |
mbatuku2: Thanks for the reply. Note that I have two functions I'm trying to use, salut() and mo(). If I call the functions in this order: salut() mo() salut() will work while mo() will not work. If change the order like this: mo() salut() Then mo() will work while salut() will not work. All other code I add to the JavaScript does not work except the first one. that's my problem. |
Re: Please Help A Script Kiddie Out With Javascript by hollyfat(m): 1:37pm On May 31, 2016 |
donlyone: Trying using your browser console to track the error. |
Re: Please Help A Script Kiddie Out With Javascript by donlyone(m): 5:15pm On May 31, 2016 |
hollyfat: After applying all the tips I got online, I still keep getting this error on browser console : Uncaught TypeError: cannot set property 'innerHTML' of null |
Re: Please Help A Script Kiddie Out With Javascript by hollyfat(m): 5:35pm On May 31, 2016 |
donlyone:This might be due to the fact that you are trying to change the content of an element that does not exist |
Re: Please Help A Script Kiddie Out With Javascript by forap(m): 8:00pm On Jun 02, 2016 |
It will be clearer if you pasted the html code also. BTW, you should replace the switch statement in the salute function with something like this:
|
Re: Please Help A Script Kiddie Out With Javascript by Xtracoool(m): 8:52pm On Jun 02, 2016 |
'x' and 'y' are suppose to be IDs of HTML elements on your page. Check that the values you pass to each of the 2 functions match IDs in your HTML. |
Re: Please Help A Script Kiddie Out With Javascript by oluwaskulboy(m): 12:32pm On Jun 03, 2016 |
DEVELOPING AN ANDROID APP, WHAT YOU SHOULD
KNOW.
http://techzone.com.ng/2016/05/05/developing-
android-app-know/ |
Re: Please Help A Script Kiddie Out With Javascript by Nobody: 2:38pm On Jun 03, 2016 |
Hi, The problem in your code is in the way you have created the functions. In JavaScript, there are two methods to create functions. In the first method, the function is saved in a variable For example, var methodName = function(){ } Using this method, you have to define the function before calling it. This will work var greet = function(){This won't work greet() //method call before method definition Method 2 is easier. You define the function like this function greet(){ This way, no matter where you place your method call, the function will run. It's safer to define your functions using the 2nd method. Make the change to the mo function in your code. I hope this explanation is clear enough. |
Re: Please Help A Script Kiddie Out With Javascript by donlyone(m): 9:44pm On Jun 03, 2016 |
Thank you guys. I really appreciate this. 1 Like 1 Share |
(1) (Reply)
Developing For Smart Watch / Get Your Custom Material Design Based Forum Sofware / Web And App Developer Needed
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 23 |