PDA

View Full Version : Can't fix this syntax error...



mgisonno
05-08-2006, 10:03 PM
So basically this code is throwing a 'syntax' error and I can't seem to figure out why. Obviosly I'm a novice javascripter, so go easy on me.

I have this in the head of the document:


<script language="JavaScript" type="text/javascript">
<!--
function button(url, color, text, width, height) {
if (target=="") {
document.write ("<div class='" + color + "button' onclick='javascript:window.location='" + url + "';' style='width: " + width + "px; height: " + height + "px;'><a href='" + url + "' class='buttonLink'>" + text + "</a></div>");
}
else if (target=="new") {
document.write ("<div class='" + color + "button' onclick='javascript:window.open('" + url + "'; return false;') style='width: " + width + "px;height: " + height + "px;'><a href='" + url + "' class='buttonLink' target='_blank'>" + text + "</a></div>");
}
}
// -->
</script>


And this in the body:


<script language="JavaScript1.2" type="text/javascript">
var target = "new";
button("http://www.urlgoeshere.com", "green", "button test", "300", "20");
</script>

Beagle
05-08-2006, 10:19 PM
document.write ("<div class='" + color + "button' onclick='javascript:window.open('" + url + "'; return false;') style='width: " + width + "px;height: " + height + "px;'><a href='" + url + "' class='buttonLink' target='_blank'>" + text + "</a></div>");

I highlighted the problem in red, should be:

document.write ("<div class='" + color + "button' onclick='javascript:window.open('" + url + "'); return false;' style='width: " + width + "px;height: " + height + "px;'><a href='" + url + "' class='buttonLink' target='_blank'>" + text + "</a></div>");

That could be it. It could also be the way you're using your quotes. Try this as well:

document.write ("<div class=\"" + color + "button\" onclick=\"javascript:window.open('" + url + "'); return false;\" style=\"width: " + width + "px;height: " + height + "px;'><a href=\"" + url + "\" class=\"buttonLink\" target=\"_blank\">" + text + "</a></div>");

mgisonno
05-08-2006, 10:26 PM
Thank you Beagle! I knew it was something stupid. I applied the ')' fix and still had the bug but i fixed the quotes and all is good now. Thanks for the ')' bug aswell though, i'm sure it might have caused something buggy.