Login | Register | FAQ
Anonymous

Single vs Double Quotes (Very Confusing!!)

+ Post a reply

2 posts Page 1 of 1


Single vs Double Quotes (Very Confusing!!)

by hiyatran » Thu Jun 07, 2012 2:25 am

The row in the table would highlight whenever I mouse over it.
This works perfectly in HTML but I would like to convert from HTML code to Javascritp code to make it more dynamic.
Code: Select all
<html>
<body>

<TABLE border=1>
<TR bgcolor="#FFFFFF" onMouseOver="this.bgColor='gold';" onMouseOut="this.bgColor='#FFFFFF';">
   <TD>Mauritania</td><TD>21N</TD><TD>24N</TD><TD>&nbsp;</TD><TD>&nbsp;</TD>
</TR>
<TR bgcolor="#FFFFFF" onMouseOver="this.bgColor='gold';" onMouseOut="this.bgColor='#FFFFFF';">
   <TD>Myanmar</td><TD>&nbsp;</TD><TD>M TBA</TD><TD>M TBA</TD><TD>&nbsp;</TD>
</TR>
<TR bgcolor="#FFFFFF" onMouseOver="this.bgColor='gold';" onMouseOut="this.bgColor='#FFFFFF';">
   <TD>Nepal</td><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>M TBA</TD>
</TR>
</TABLE>

</body>
</html>




I tried to convert it to Javascript but it only gives me a blank screen.
This is very frustrating because I don't know where I'm going wrong.
Any comments of suggestions would be greatly appreciated.

Code: Select all
<html>
<head>
<script type="text/javascript">

function init(){
   document.writeln('<TABLE border=1>');

   document.writeln('<TR bgcolor="#FFFFFF" onMouseOver="this.bgColor='gold';" onMouseOut="this.bgColor='#FFFFFF';">');
   document.writeln('<TD>Mauritania</td><TD>21N</TD><TD>24N</TD><TD>&nbsp;</TD><TD>&nbsp;</TD> </TR>');

   document.writeln('<TR bgcolor="#FFFFFF" onMouseOver="this.bgColor='gold';" onMouseOut="this.bgColor='#FFFFFF';">');
   document.writeln('<TD>Myanmar</td><TD>&nbsp;</TD><TD>M TBA</TD><TD>M TBA</TD><TD>&nbsp;</TD></TR>');

   document.writeln('<TR bgcolor="#FFFFFF" onMouseOver="this.bgColor='gold';" onMouseOut="this.bgColor='#FFFFFF';">');
   document.writeln('<TD>Nepal</td><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>M TBA</TD></TR></TABLE>')';
}
</script>
</head>

<body onload="init()">
</body>
</html>
User avatar

hiyatran

  • Posts: 6
  • Joined: Thu Jun 07, 2012 2:22 am

Re: Single vs Double Quotes (Very Confusing!!)

by XainPro » Thu Jun 07, 2012 9:33 am

yah its confusing and it also give a syntax error you have to use escape characters with these characters
Code: Select all
Code    Outputs
\'    single quote
\"    double quote
\\    backslash
\n    new line
\r    carriage return
\t    tab
\b    backspace
\f    form feed

for further detail please see
http://www.w3schools.com/js/js_special_characters.asp
User avatar

XainPro

  • Posts: 3616
  • Joined: Fri Feb 17, 2012 8:10 pm


+ Post a reply

Page 1 of 1

?>