Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can't fix this syntax error...

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

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    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>");

  • #3
    New to the CF scene
    Join Date
    May 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •