|
Hi, I've been learning the basics of javascript, and I am having trouble getting a BASIC code working. Basically, I'm trying to include text and variables in output.innerhtml but it does not work correctly. JSlint gives the error "SYNTAX ERROR: missing ; before statement." Anyways, the coding: <html> <head> </head> <body> <form> Level name: <input type="text" name="levelName" /> <br /> Type (Enter "gold" for gold, "plat" for platinum): <input type="text" name="levelType" /> <br /> Author: <input type="text" name="author" /> <br /> Download Link: <input type="text" name="downloadLink" /> <br /> <input type="button" name="submit" value="Click" onClick="releasedLevels(this.form)"> <br /> </form> <script type="text/javascript"> function releasedLevels (form) { var levelName = form.levelName.value; var levelType = form.levelType.value; var author = form.author.value; var downloadLink = form.downloadLink.value; var output = document.getElementById('output_area'); output.innerHTML = "The level name is " + levelName ", the type is " + levelType ", the author is " + author ", and you can download it at " + downloadLink; } </script> <div id="output_area"> </div> </body> </html> Thanks. EDIT: The text wasn't readable when I had it wrapped in code tags, so I'm just posting it plain in the post.
Last Edit: Jun 24, 2009 0:12:31 GMT by perishingflames
|
|
|
|
Your error is on this line:
output.innerHTML = "The level name is " + levelName ", the type is " + levelType ", the author is " + author ", and you can download it at " + downloadLink;
And unfortunately it's 3 things that are missing I've put them in red so that you know what they are:
output.innerHTML = "The level name is " + levelName [red]+[/red] ", the type is " + levelType [red]+[/red] ", the author is " + author [red]+[/red] ", and you can download it at " + downloadLink;
|
|
|
|
Ah, ok, didn't know that a plus is needed before and after. Also, should I be using document.write, or is output.innerhtml alright in this situation?
|
|
|
|
Whichever you want!
|
|
|
|
Ah, ok, didn't know that a plus is needed before and after. Also, should I be using document.write, or is output.innerhtml alright in this situation? Actually in this situation output.innerHTML is the only choice among those two. Doing it the other way would cause the page to change with the written text being all that shows up.
|
|
|
|
Ok, thanks for the help you guys. Anyways, now that I have the basics of it down, I am trying to make it display some html in plain text (without processing it). I have it almost as I want it, but I don't know how to make it show quotation marks without the javascript actually processing the quotation marks when it runs the function. I have it using single quotation marks at the moment, but my goal is actually to have it display regular quotes on the page. Coding now: output.innerHTML = "<li class='" +levelType + "'><a href='" + downloadLink + "'>" + levelName + "</a> by " + author; And a demo page: www.perishingflames.com/Assorted/untitled.html (not a rick roll, I swear ) Thanks.
|
|
|
|
Nevermind, got it. Learned that you can use ' in place of " to surround the text, so I just had to flip-flop them. output.innerHTML = '<li class="' +levelType + '"><a href="' + downloadLink + '">' + levelName + '</a> by ' + author; Next thing to learn: how to create an admin panel and have it output the innerhtml to the headers/footers Any tips where to start learning besides simply trying to make sense of the coding of an actual admin panel code?
Last Edit: Jun 24, 2009 3:45:10 GMT by perishingflames
|
|
|
|
output.innerHTML = "<li class='" +levelType + "'><a href='" + downloadLink + "'>" + levelName + "</a> by " + author; that's what your HTML looks like change the <'s to < and the >'s to >
Last Edit: Jun 24, 2009 3:45:59 GMT by Eric
|
|
|
|
Eric,
For now, I just wanted it to display the html (it shows the < as a <, but if you actually use those in the innerhtml, using the form will actually create the list item) rather than actually insert and process the html.
|
|
|
|
I'm not really sure what you mean.
|
|
|
|
Perishing: One additional thing about quotes... you can "escape" quote by using a backslash (\). So, this is valid: item.innerHTML += "And she told me \"to suck it.\" I was appalled."; Anyways... There's an admin editable tut, or two, in the database here. Just take a look at them.
|
|
|
|
|
Oh, if that's what you're trying to accomplish you can use " as well.
|
|
|