Please see my code here: https://repl.it/#AliMosallaei1/Just-A-Test (it uses localStorage and has a lot of parts so I can't really put it in the SO sandbox)
When you add a class and click on the Name of the class, it should execute the edit() function in grade.js. However, instead, it is throwing a TypeError, saying edit is not a function. What could be causing this issue?
EDIT: The file that needs help is the grade.js, just to clarify. The major things to look at are the edit(i) function and the big for loop.
This answer should be on the comment section but I don't have the enough reputation.
Try renaming your "edit()" function to "edit2()" or something else, this should work.
Related
My friends and I are trying to make a website from scratch and we have barely ever touched html. We have got a private domain, but we just started and don't seem to know how to define this unexpected token found on line 29. Any help would be well appreciated. This is the only thing limiting us to run our code (I think).
Sign out
This is what pops up whenever trying to run the code:
Picture of code on line 29:
line 28-44
Based on the images given (more would be nice, or code samples), I can see the function signOut() being called, but I can't see a { after it. Inside your <script> tags, the function call should be function signOut(){ //Your code }. Please see if it works.
In addition to this, I'd check that all tags are ended (for example <script> should have a matching </script> tag after the necessary JS). As others have said, as well, make sure the file ends with .html!
I wrote a script which load data compile it with handelbars to a string. Then I add these elements to the DOM and want to give them some eventlisteners and functions like draggable but it doesn’t work. It seems that it work asynchronously and not synchronously like I read here in many other posts. Can someone give me a hint where i think wrong??
I posted the code here
http://jsfiddle.net/Zjx35/
I would be really glad for any hint.
You look to have mis-typed your class name.
//
<div style="position:absolute; top:{{posy}}; left:{{posX}}" class="d_entity">
//
$(".p_entity").draggable().css("background","red");
Updated Example: http://jsfiddle.net/Zjx35/1/
I saw several specific questions about this problem - getting typeerror object doesn't support this property or method in IE8, each with its specific answer.
Suppose I have a large website with lots of code ... I don't know what specific snippet is causing this error.
Is there a general method to debug this? I've tried with the IE Developer Tools, and it doesn't break on error. Is this caused by incorrect javascript syntax? Should I try something like js lint?
What's the correct, general way to identify and deal with this problem?
OK, so I turned to the age old solution and started to delete massive chunks of code from my project until the problem was "fixed". This helped me locate the problematic file.
I then proceeded to delete function by function until I found this little snippet: str.trim(). A quick search turned this up.
Update: Actually, I just realized something ... the problem was just a normal exception, and passing it to alert() masked the details. If you let such exceptions go to the top, then whatever browser you use will display useful line information. So, the next time it happens to me, I'm going to look for a way to make the exceptions fly high outside of the top level function. The catch wasn't in my code, it was jQuery, so I'm still not quite sure how to do it.
I have a simple script that should cause one of three divs to be visible while the other two are not. The function that does the work is called like so:
onchange="switch(this);"
Firebug indicates that there is an error with this text:
Javascript Error: missing { before switch body
The erroneous code it indicates is line one of my .php file where the doctype is defined like so:
<!doctype html>
The funny thing here is that I have another page with the same doctype and a script that is virtually identical which works 100%. The only differences between the two pages are that in the one that does work, I call the script from
One more thing about the Firebug output: On the page that works, the firebug script window shows the javascript like so:
function onclick(event) {
switch(this);
}
Now, on the page where the script doesn't work, Firebug shows no output that has anything to do with onchange, onclick, or anything else. It just shows the code from my javascript file and tells me I am missing the opening bracket to the function when it is clear as day that it's there. Perhaps, even with the script in the head of my main php file, something odd is happening with scope, making the defined function invisible to the callers. Any ideas?
1: why would Firebug tell me the error is on line 1 where the doctype is defined when the function that fails isn't even in the same file?
2: Does the doctype effect the way that javascript runs, and how do I debug it if it does?
I would prefer to continue using only HTML5 for this project and use a javascript file for backwards compatibility. Any help is very welcome!
P.S. I am running Ubuntu 11.10 with Apache2, PostgreSQL, and PHP5. Everything works perfectly outside of this one javascript issue.
EDIT: Totally stupid question, but I guess these things happen sometimes. As stated in the answers, switch is a keyword in Javascript and changing the name of my function fixed the problem. I really should have noticed that since my editor highlights keywords in brown...
I am not deleting this post (unless someone else suggests I do) in case someone else out there runs into the same problem. I am giving the answer to the guy who answered it first because his answer also explained the reason why I was getting the error messages I was getting, which is probably more helpful in the long run than a simple awareness of switch statements.
This error has nothing to do with your doctype or HTML5. It occurs because switch is a reserved word used for switch statements; you cannot name a function switch.
So when you do switch(this) the JavaScript engine is expecting you to follow that up with the rest of the switch statement, including the opening {, the switch body, and then the closing }. When you don't do that, it throws the given error.
The error is on "line 1" because you used an inline event handler, which in Firebug's mind is a JavaScript file with one line---that line simply being switch(this);. Firebug does not deal in line numbers of HTML files, only those of JavaScript files---whether they be real JavaScript files, or "virtual" ones generated by inline event handlers.
switch is a keyword in javascript, rename your function to something else like myswitch.
switch is a keyword in Javascript
I'm facing a problem: I have a javascript function in my application.js but it's not working correctly. Always when I click in the button, it gives me this error in the firebug:
goto_nex_photo is not defined
but I have this function implemented in the application.js. I don't what is going wrong. I will post the code of application.js and the gallery_detail.html.erb:
https://gist.github.com/902973
Line 600 you have a random F at the start of the line.
That is a lot of code to work though. To much for me but I can offer you a method to find what is broken. Mostly likely there is something wrong with some piece of code above that function in the javascript.
Start by moving that function to the top of the script... ... then move it subsequently down ... one method at a time until you find the method that had the bad code...
Another thing you could do is look at the RAW html actually outputted and make sure that the javascript include for the function is there... I did actually check your code and it looks like all your curly braces match up...