Click to See Complete Forum and Search --> : [RESOLVED] script error


sagnetwork
01-01-2008, 12:56 PM
//Contents for menu 2, and so on
var menu2=new Array()

the line with the error:

menu2[0]='<bgColor='#FBE1BD>'<img border="0" src="brown.jpg" width="10" height="10"></a>'


menu2[1]='<a href="http://msnbc.com">MSNBC</a>'
menu2[2]='<a href="http://news.bbc.co.uk">BBC News</a>'

the bottom 2 menus work, but I want it to display a 10x10 brown block, then when its clicked on the background will change to brown, but I can not get menu2[0] to function right. Can someone see where my problem is?

Thanks

bradgrafelman
01-01-2008, 01:13 PM
Moved to the ClientSide Technologies forum.

Your problem is with unescaped delimiters (the literal single quotes within the string). I would recommend changing them to double quotes (as you use for all of the other HTML attributes) as well is fixing the order (you have >' instead of '>).

sagnetwork
01-01-2008, 01:18 PM
menu2[0]='<bgColor='#FBE1BD>'<img border="0" src="brown.jpg" width="10" height="10"></a>'


Should it look like this:

menu2[0]='<bgColor='#FBE1BD'><img border="0" src="brown.jpg" width="10" height="10"></a>'

thanks for you help.

bradgrafelman
01-01-2008, 01:28 PM
Well you fixed the second problem I mentioned, but you still have the syntax error - you have two unescaped single quotes within the string (surrounding the HTML attribute).

If you don't know what that means, think of it like this: surrounding the string on the outside, you use single quotes - this tells the script engine where the string starts and stops. Now, within that string, you're currently trying to say that there are single quotes around #FBE1BD. The problem is, however, that when the script engine comes to that single quote, it thinks you're specifying the end of the string, thus the syntax errors. What you need to do is either a) "escape" the quote (prepend it with a backslash so that the script engine knows that you don't want to end the string, you want a literal single quote placed inside the string at that point), or b) switch the single quotes in the HTML to double quotes (as the rest of your attributes use).

sagnetwork
01-01-2008, 01:34 PM
ok, im sorry im very new at this so I need to ) this before or after any "


original
menu2[0]='<bgColor='#FBE1BD'><img src="brown.jpg"></a>'


corrected

menu2[0]='<bgColor=('#FBE1BD)'><img border=("0)" src=("brown.jpg)">'

bradgrafelman
01-01-2008, 01:38 PM
No, I said prepend a backslash, like so: alert('This doesn't work!'); // broken, quote needs to be escaped:

alert('This doesn\'t work!'); // now it DOES work - quote was escaped (backslash placed before it)

sagnetwork
01-01-2008, 01:48 PM
Im tring to understand this, please bear with me, this is my first time doing this


menu2[0]="<bgColor=\"#FBE1BD\")><img border=\"0\" src=\"brown.jpg\">"

does this look better?

bradgrafelman
01-01-2008, 02:10 PM
You still have a ')' in there... get ri dof that and it should be fine. Alternatively, you could have done:

menu2[0]='<bgColor="#FBE1BD"><img border="0" src="brown.jpg">'or you could have kept the single quotes and escaped them: menu2[0]='<bgColor=\'#FBE1BD\'><img border="0" src="brown.jpg">'

sagnetwork
01-01-2008, 02:13 PM
Thanks so much for your help, im just learning this, so its something new to me and I figured someone here would be able to help me out.

Thanks again