Reputation: 329
I'm returning a syntax error on line 9 (screenshot of IDE: http://dl.dropbox.com/u/2578642/Error.png).
I'm complete noob and can't see the error, anyway, here's the code:
<input type = "image" id = "myImage" src = "One.jpg" height ="130" width="173" border="0" Alt="Submit Form" onclick="var fileref=document.createElement('script');fileref.setAttribute('type','text/javascript'); fileref.setAttribute('src', 'http://MYCONTENTLOCKER.com/guid?:1234567890'); showMessage(); setTimeout(changeImage, 30000)">
<br>
<span id = "message" style="display:none">You have completed this part!</span>
<script type = "text/javascript">
var count = 0;
function showMessage () {
if (count > 0) { // line 9
document.getElementById("message").style.display="block";
}
count ++;
}
function changeImage() {
document.getElementById("myImage").src = "Two.jpg"
}
</script>
Thanks for any help!
Upvotes: -1
Views: 168
Reputation: 76786
Well, it seems to work fine for me.
That said, the only thing I can possibly imagine being wrong is the >
on that line is somehow getting escaped as an HTML entity before the page is served. Have you checked that the output of "view source" is indeed the same exact code you wrote?
Technically script
elements and other elements with non-CDATA content containing "special" characters should have the content enclosed in a CDATA section. If your HTML code gets run through an XML parser at some point, it will choke on characters like <
,>
, and &
.
With the CDATA section in the script, and the markup written as proper XHTML, the code would look something like this:
<html><head></head><body>
<input type="image" id="myImage" src="One.jpg" height="130" width="173" border="0" Alt="Submit Form" onclick="imageClick()" />
<br />
<span id="message" style="display:none">You have completed this part!</span>
<script type="text/javascript">
/* <![CDATA[ */
var count = 0;
function showMessage () {
if (count++ > 0) {
document.getElementById("message").style.display="block";
}
}
function changeImage() {
document.getElementById("myImage").src = "Two.jpg"
}
function imageClick() {
var fileref = document.createElement('script');
fileref.setAttribute('type','text/javascript');
fileref.setAttribute('src', 'http://MYCONTENTLOCKER.com/guid?:1234567890');
showMessage();
setTimeout(changeImage, 30000);
}
/* ]]> */
</script>
</body></html>
Update: OK, I just realized that you're getting the error in your IDE, not necessarily in the browser. I don't know if the IDE is complaining about the unescaped triangle bracket or not, but i suspect it might be. I don't know if it's smart enough to acknowledge the CDATA section though. I'm curious if this will appease it. What IDE is that, anyway?
Upvotes: -1
Reputation: 324
Just realized that was your whole code. Would you please declare a valid HTML file? The highlighted this should've been a dead giveaway.
Upvotes: 0
Reputation: 227310
Your JavaScript code looks fine, and the only thing I see that could be causing an issue is the space before and after the =
in the HTML attributes.
<script type = "text/javascript">
Should be:
<script type="text/javascript">
So, your code should look like this (I also suggest indenting your code. Makes it easier to read):
<input type="image" id="myImage" src="One.jpg" height="130" width="173" border="0" Alt="Submit Form" onclick="var fileref=document.createElement('script');fileref.setAttribute('type','text/javascript'); fileref.setAttribute('src', 'http://MYCONTENTLOCKER.com/guid?:1234567890'); showMessage(); setTimeout(changeImage, 30000)">
<br>
<span id="message" style="display:none">You have completed this part!</span>
<script type="text/javascript">
var count = 0;
function showMessage () {
if (count > 0) {
document.getElementById("message").style.display="block";
}
count++;
}
function changeImage() {
document.getElementById("myImage").src = "Two.jpg"
}
</script>
I'm not sure if that's the problem, but that's all I could think of.
Upvotes: 1
Reputation: 35417
The code you posted is syntactically fine. I highly recommend you look into the script that you're "dynamically" loading through your inline onclick
event handler.
Upvotes: 2