473,395 Members | 1,411 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

put statement javascript as nested

oranoos3000
107 100+
hi
i d like to create a table of safe color for web as online.
i show a table of safe color on the page and i want to by clicking user on the links
background-color document is changed but sorry my script doesnt work
and by running that in Mozila firefox in menu tools->javascirpt consol
in line that function bg valu send show error
my script is as follow:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <title>Untitled Document</title>
  6. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  7. </head>
  8.  
  9. <body onLoad="document.bgColor='#ff0000'">
  10. <script type="text/javascript">
  11. <!--
  12. function bg(c)
  13. {
  14. document.bgColor="'#"+c+"'";
  15. }
  16. var t="";
  17. ar_color=new Array('00','33','66','99','CC','FF');
  18. t+='<table>'
  19. for(i=0;i<6;++i)
  20. {
  21. for(j=0;j<6;++j)
  22. {
  23. t+='<tr>';
  24. for(k=0;k<6;++k)
  25. {
  26. color=ar_color[i]+ar_color[j]+ar_color[k];
  27. t+='<td bgColor="#'+color+'"><a href="#" onMouseOver="bg('+color+')" > #'+color+'</a></td>';
  28. }
  29. t+='</tr>';
  30. }
  31. }
  32. t+='</table>';
  33. document.write(t);
  34. document.close();
  35. //-->
  36. </script>
  37. </body>
  38. </html>
thanks for your help
Aug 22 '09 #1
3 1507
gits
5,390 Expert Mod 4TB
change line 14 to:

Expand|Select|Wrap|Line Numbers
  1. document.bgColor="#"+c;
  2.  
and line 27 to:

Expand|Select|Wrap|Line Numbers
  1. t+='<td bgColor="#'+color+'"><a href="#" onclick="bg(\''+color+'\')" > #'+color+'</a></td>';
kind regards
Aug 22 '09 #2
oranoos3000
107 100+
hi
thanks for your answer but why

Expand|Select|Wrap|Line Numbers
  1. bg(\''+color+'\')"
?
and why not

Expand|Select|Wrap|Line Numbers
  1. onclick="bg('"+color+"')"
in follow line
Expand|Select|Wrap|Line Numbers
  1. t+='<td bgColor="#'+color+'"><a href="#" onclick="bg(\''+color+'\')" > #'+color+'</a></td>';
Sep 1 '09 #3
gits
5,390 Expert Mod 4TB
when you use it your mentioned way then you might see that the string is terminated too early and throws a JavaScript error, it would look like this:

Expand|Select|Wrap|Line Numbers
  1. t+='<td bgColor="#'+color+'"><a href="#" onclick="bg('"+color+"')"
so after bg(' the string is terminated unless you escape the quote correctly

kind regards
Sep 1 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

47
by: Andrey Tatarinov | last post by:
Hi. It would be great to be able to reverse usage/definition parts in haskell-way with "where" keyword. Since Python 3 would miss lambda, that would be extremly useful for creating readable...
26
by: Joe Stevenson | last post by:
Hi all, I skimmed through the docs for Python, and I did not find anything like a case or switch statement. I assume there is one and that I just missed it. Can someone please point me to the...
4
by: Prowler | last post by:
In the application we are currently building, we need to write positioning code on-the-fly, based upon the screen offset of the element in the AS/400 application which drives the Web app. The 400,...
6
by: JS | last post by:
In this sample code: if(n==0&&args>1){ for(i=num;args>i+1;i++){ s.length = 0; opt = document.createElement('OPTION'); s.appendChild(opt); opt.value = ""; opt.text = "\74-- Vælg --"; }
15
by: grunar | last post by:
After some thought on what I need in a Python ORM (multiple primary keys, complex joins, case statements etc.), and after having built these libraries for other un-named languages, I decided to...
8
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
19
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without...
22
by: Cogito | last post by:
For the first time, I'm attempting to write a small Javascript program using one on the online reference sites. I need some confirmation as to the behaviour of the break statement. In the...
33
by: =?Utf-8?B?RE9UTkVUR1VZ?= | last post by:
Hello, In vb.net there is a with statement, Is there are similar constructor in c#?
0
by: Tommy Jakobsen | last post by:
Hi. Is there a problem when trying to use Javascript on a nested masterpage? On my masterpage, i've got this in the <head>: <asp:ContentPlaceHolder ID="HeadContent" runat="server" /> And on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.