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!
Related
This is a silly question but I can't seem to find an example that works. Basically I want to add a section on my website for the customer to check their USPS Tracking Number Status; USPS only provides an XML API while I need HTML / JS for this to work.
I need to create a text box that takes a 22 character (or less) alphanumeric variable so that when you click a "Submit" button, it will put the variable into this link.
Sadly, I need the entire script code from the and tags. I have tried every example I found and none of them worked in the sandbox, likely because I am missing some basic tags. I have come to the conclusion that I have no clue what I'm doing so please do not get frustrated by the simplicity of my question.
https://tools.usps.com/go/TrackConfirmAction_input?strOrigTrackNum={xxx} where xxx is must be the variable. Every example of code I have found will append to a link, but not put the variable inside the {}. I have been looking and tried a ton of different examples, but being far from a codemonkey I could really use some help. I apologize in advance because I know this is simple but I don't know what I am doing wrong except for trying to do something I have no business trying to do as I'm not a developer. Thanks in advance!
To provide the answer to my own question here us the correct code,
<script type="text/javascript">
function goToPage() {
var page = document.getElementById('USPS_Tracking_Number').value;
window.location = "https://tools.usps.com/go/TrackConfirmAction_input?>strOrigTrackNum=" + page;
}
</script>
I am new to javascript and have been working overnight to see how I can fix this error on IE: Here's the question I asked here yesterday: How to fix this jquery function to work in IE?
After spending more than 20 hours I still can't find out why it wouldn't render parts of my page properly.
At the very least I thought I could find a way to get the errors so I can fix them or do a separate javascript file just for IE, but no luck.
How do I see error messages for my script?
I used F12 to see the developer console but no help there, it won't even tell me what's wrong.
I am using IE 8 and 9.
I know that there could be many things wrong with this and I appreciate your patience in advance for helping me out. Thanks!
You have invalid HTML including many invisible characters within the head section which is also blocking the W3C HTML Validator from getting past the first few errors.
When I copied your source code into my text editor, I found a bunch of invalid invisible characters. Did you cut/paste your JavaScript from someplace like a web-page? The invisibles only appear in front of your custom written scripts in the <head> and nowhere else. This could certainly explain a lot, including the validation error about a misplaced </head> tag. Go back to your editor and delete the indentations on every single line within the entire <head></head> section, then re-indent each line from scratch.
I also see an invalid closing tag, </label6>.
Remove the invisible characters, fix the invalid HTML, and see what IE does.
Moving forward, get yourself a powerful text editor that will allow you to see invisible characters so you can delete them and properly indent as needed. Otherwise, I recommend re-typing your code rather than cutting & pasting.
For JavaScript errors, the best is to see the 'Console' tab for records.
If IE's one isn't showing anything, maybe you could try using FireBug Lite, adding the following script after <head> (YES, put it as first thing, so it loads first than anything else).
<script type="text/javascript" src="https://getfirebug.com/firebug-lite.js"></script>
On side note, maybe isn't a JS problem and yes something about running code locally. IE has some policies that mostly block client-side code from running. (Remember those annoying ActiveX prompts?). Check Intranet configuration on Settings.
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...
I have been looking around for a HTML formatter to incorporate with a project I am doing. I need it to be written in Javascript since I want the formatting done on the client side.
The problem is, the few that I have tried don't work very well... For example:
http://www.davidpirek.com/blog/html-beautifier-jquery-plugin : Has a problem with one of the For loops (in the cleanAsync function). Chrome says "unexpected token ILLEGAL"
JS Beautifier on GitHub : When I have links in the HTML it will put a newline character after it. The problem is, I have a period directly after the link in some cases and it will add a space between the link text and the period in the sentence. I tried poking around to fix it but I could not.
Are there any others, or does anyone have recommendations to fix the above two?
EDIT:
This is for editing code, so I just need something to tab in the lines, etc. The code output will go in a textarea.
A few to look at, all have working demos:
http://alexgorbatchev.com/SyntaxHighlighter/
http://shjs.sourceforge.net/
http://jush.sourceforge.net/
http://dojotoolkit.org/reference-guide/dojox/highlight.html
use https://github.com/beautify-web/js-beautify and pass your code to html_beautify() method.