473,382 Members | 1,692 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,382 software developers and data experts.

I need help for the java script posted---can anyone telme where is the error

2
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. document.write('<table width="30%" border="0" cellspacing="0" cellpadding="10">' )
  3. document.write('<tr>' )
  4. document.write('<td width="30%">' )
  5. document.write('<div id="menu">')
  6. document.write('<a href= "sports.htm" lass="itemLink">&nbsp;&nbsp;&nbsp;Sports </a> ' )
  7. document.write('<div id="box1"> this is some content for the first item!</div>' )
  8. document.write('<a href="javascript:;" onclick="showOrHide('box2', 'img2')" class="itemLink"><img src="plus.png" name="img2" width="10" height="10" border="0" id="img2"/>&nbsp;Item 2 </a>' )
  9. document.write('<div id="box2"> <a href= "travel.htm">Travel</a><br/>
  10. <a href= "egypt.htm" >Egypt</a></div>' )
  11. document.write('<a href="javascript:;" onclick="showOrHide('box3', 'img3')" class="itemLink"><img src="plus.png"  name="img3" width="10" height="10" border="0" id="img3"/>&nbsp;Item 3 </a>' )
  12. document.write('<div id="box3"> this is some content for the second item!</div>' )
  13. document.write('<a href="javascript:;" onclick="showOrHide('box4', 'img4')" class="itemLink"><img src="plus.png"  name="img4" width="10" height="10" border="0" id="img4"/>&nbsp;Item 4 </a>' )
  14. document.write('<div id="box4"> this is some content for the third item!</div>')
  15. document.write('<a href="javascript:;" onclick="showOrHide('box5', 'img5')" class="itemLink"><img src="plus.png" name="img5" width="10" height="10" border="0" id="img5"/>&nbsp;Item 5 </a>' )
  16. document.write('<div id="box5"> this is some content for the fourth item!</div>')
  17. document.write('</div>')
  18. document.write('/td')
  19. document.write(</tr>')
  20. document.write(</table>')
  21. </script>
Nov 3 '07 #1
4 1451
acoder
16,027 Expert Mod 8TB
You need to escape the single quotes within single quotes. You can use single and double within each other but when you use the same quote, then it must be escaped otherwise it would be seen as the end of the string.
Nov 3 '07 #2
Ferris
101 100+
You need to escape the single quotes within single quotes. You can use single and double within each other but when you use the same quote, then it must be escaped otherwise it would be seen as the end of the string.
Exactly!

Here's the right code:

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2.       document.write('<table width="30%" border="0" cellspacing="0" cellpadding="10">' )
  3.       document.write('<tr>' )
  4.       document.write('<td width="30%">' )
  5.       document.write('<div id="menu">')
  6.       document.write('<a href= "sports.htm" lass="itemLink">&nbsp;&nbsp;&nbsp;Sports </a> ' )
  7.       document.write('<div id="box1"> this is some content for the first item!</div>' )
  8.       document.write('<a href="javascript:;" onclick="showOrHide(/"box2/", /"img2/")" class="itemLink"><img src="plus.png" name="img2" width="10" height="10" border="0" id="img2"/>&nbsp;Item 2 </a>' )
  9.       document.write('<div id="box2"> <a href= "travel.htm">Travel</a><br/><a href= "egypt.htm" >Egypt</a></div>' )
  10.       document.write('<a href="javascript:;" onclick="showOrHide(/"box3/", /"img3/")" class="itemLink"><img src="plus.png"  name="img3" width="10" height="10" border="0" id="img3"/>&nbsp;Item 3 </a>' )
  11.       document.write('<div id="box3"> this is some content for the second item!</div>' )
  12.       document.write('<a href="javascript:;" onclick="showOrHide(/"box4/", /"img4/")" class="itemLink"><img src="plus.png"  name="img4" width="10" height="10" border="0" id="img4"/>&nbsp;Item 4 </a>' )
  13.       document.write('<div id="box4"> this is some content for the third item!</div>')
  14.       document.write('<a href="javascript:;" onclick="showOrHide(/"box5/", /"img5/")" class="itemLink"><img src="plus.png" name="img5" width="10" height="10" border="0" id="img5"/>&nbsp;Item 5 </a>' )
  15.       document.write('<div id="box5"> this is some content for the fourth item!</div>')
  16.       document.write('</div>')
  17.       document.write('</td>')
  18.       document.write('</tr>')
  19.       document.write('</table>')
  20. </script>
  21.  
By the way,you also have some syntax errors like this:
Expand|Select|Wrap|Line Numbers
  1. document.write(</table>')
  2.  
hope it helps.
Nov 3 '07 #3
nirupa
2
I have code to "Click & Expand Menus" within a Table
According to the requirement i need to have 2 Js.Files( 1. menu_function.js and 2. menu_table.js) & a HTML main page.

menu_function.js
Expand|Select|Wrap|Line Numbers
  1. function showOrHide(eId, thisImg, state) {
  2.     if (e = document.getElementById(eId)) {
  3.         if (state == null) {
  4.             state = e.style.display == 'none';
  5.             e.style.display = (state ? '' : 'none');
  6.         }
  7.         //...except for this, probably a better way of doing this, but it works at any rate...
  8.         if (state == true){                
  9.             document.getElementById(thisImg).src="minus.png";
  10.         }
  11.         if (state == false){
  12.             document.getElementById(thisImg).src="plus.png";
  13.         }
  14.     }
  15. }
  16. //function to hide all "boxes"
  17. function hideAll(){
  18.     document.getElementById('box1').style.display = 'none';
  19.     document.getElementById('box2').style.display = 'none';
  20.     document.getElementById('box3').style.display = 'none';
  21.     document.getElementById('box4').style.display = 'none';
  22.     document.getElementById('box5').style.display = 'none';
  23. }
  24.  
menu_table.js
Expand|Select|Wrap|Line Numbers
  1.       document.write('<table width="30%" border="0" cellspacing="0" cellpadding="10">' )
  2.       document.write('<tr>' )
  3.       document.write('<td width="30%">' )
  4.       document.write('<div id="menu">')
  5.       document.write('<a href= "sports.htm" class="itemLink">&nbsp;&nbsp;&nbsp;Sports </a> ' )
  6.       document.write('<div id="box1"> this is some content for the first item!</div>' )
  7.       document.write('<a href="javascript:;" onclick="showOrHide(/"box2/", /"img2/")" class="itemLink"><img src="plus.png" name="img2" width="10" height="10" border="0" id="img2"/>&nbsp;Item 2 </a>' )
  8.       document.write('<div id="box2"> <a href= "travel.htm">Travel</a><br/><a href= "egypt.htm" >Egypt</a></div>' )
  9.       document.write('<a href="javascript:;" onclick="showOrHide(/"box3/", /"img3/")" class="itemLink"><img src="plus.png"  name="img3" width="10" height="10" border="0" id="img3"/>&nbsp;Item 3 </a>' )
  10.       document.write('<div id="box3"> this is some content for the second item!</div>' )
  11.       document.write('<a href="javascript:;" onclick="showOrHide(/"box4/", /"img4/")" class="itemLink"><img src="plus.png"  name="img4" width="10" height="10" border="0" id="img4"/>&nbsp;Item 4 </a>' )
  12.       document.write('<div id="box4"> this is some content for the third item!</div>')
  13.       document.write('<a href="javascript:;" onclick="showOrHide(/"box5/", /"img5/")" class="itemLink"><img src="plus.png" name="img5" width="10" height="10" border="0" id="img5"/>&nbsp;Item 5 </a>' )
  14.       document.write('<div id="box5"> this is some content for the fourth item!</div>')
  15.       document.write('</div>')
  16.       document.write('</td>')
  17.       document.write('</tr>')
  18.       document.write('</table>')
  19.  
Now,
The HTML:

[HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Menu menu</title>
<script language="Javascript" type="text/javascript" src="menu_function.js">
</script>
<link rel="stylesheet" type="text/css" href="menu.css">
</head>
<body onload="hideAll();">
<script language="Javascript" type="text/javascript" src="menu_tab.js">
</script>
</body>
</html>[/HTML]

The problem is the submenus are not getting loaded.......when clicked on the menu...

If the js files are not included in the HTML it works fine:..here is the code

[HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Menu menu</title>
<script language="Javascript" type="text/javascript">
<!--
//altered from example posted previously...
function showOrHide(eId, thisImg, state) {
if (e = document.getElementById(eId)) {
if (state == null) {
state = e.style.display == 'none';
e.style.display = (state ? '' : 'none');
}
//...except for this, probably a better way of doing this, but it works at any rate...
if (state == true){
document.getElementById(thisImg).src="minus.png";
}
if (state == false){
document.getElementById(thisImg).src="plus.png";
}
}
}
//function to hide all "boxes"
function hideAll(){
document.getElementById('box1').style.display = 'none';
document.getElementById('box2').style.display = 'none';
document.getElementById('box3').style.display = 'none';
document.getElementById('box4').style.display = 'none';
document.getElementById('box5').style.display = 'none';
}
//!-->
</script>
<style type="text/css">
<!--
/* styles for the links...*/
a.itemLink {
display: block;
font-family:Arial, Helvetica, sans-serif;
font-size:small;
background-color:#CCCCCC;
margin:5px;
padding:2px;
text-decoration: none;
}
/* top level container...*/
#menu {
position: relative;
width:250;
background-color:#999999;
padding:2px;
}
/* affects all divs in #menu*/
#menu div {
margin-left:25px;
margin-right:25px;
}
-->
</style>
</head>
<body onload="hideAll();">
<table width="30%" border="0" cellspacing="0" cellpadding="10">
<tr>
<td width="30%"><div id="menu"><a href= "sports.htm" class="itemLink">&nbsp;&nbsp;&nbsp;Sports </a>
<div id="box1"> this is some content for the first item!</div>

<a href="javascript:;" onclick="showOrHide('box2', 'img2')" class="itemLink"><img src="plus.png" name="img2" width="10" height="10" border="0" id="img2"/>&nbsp;Item 2 </a>
<div id="box2"> <a href= "travel.htm">Travel</a><br/>
<a href= "egypt.htm" >Egypt</a></div>
<a href="javascript:;" onclick="showOrHide('box3', 'img3')" class="itemLink"><img src="plus.png" name="img3" width="10" height="10" border="0" id="img3"/>&nbsp;Item 3 </a>
<div id="box3"> this is some content for the second item!</div>
<a href="javascript:;" onclick="showOrHide('box4', 'img4')" class="itemLink"><img src="plus.png" name="img4" width="10" height="10" border="0" id="img4"/>&nbsp;Item 4 </a>
<div id="box4"> this is some content for the third item!</div>
<a href="javascript:;" onclick="showOrHide('box5', 'img5')" class="itemLink"><img src="plus.png" name="img5" width="10" height="10" border="0" id="img5"/>&nbsp;Item 5 </a>
<div id="box5"> this is some content for the fourth item!</div>
</div></td>

</tr>
</table>
</body>
</html>
[/HTML]
* I need to put the menu table in the js file...has im gonna use it in multiple pages*
Request to guide me what needs to be done......
Nov 3 '07 #4
gits
5,390 Expert Mod 4TB
hi nirupa ...

please use our code-tags when posting code ... so that your code would be much easier to read ...

example:

[CODE=javascript] your code here [/code]

kind regards
Nov 3 '07 #5

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

Similar topics

6
by: harish | last post by:
Hi, We are developing one application for smartphone. In this we are parsing XMLs and rendering it as UI elements using smartphone SDK. Everything is working fine. Now one more requirement has...
2
by: . . | last post by:
Hi I need some help with java script . I have a ASPX page that is pulling a user message heading from the table on the page . The user message header has message body which suppose to dispay...
0
by: Gill Smith | last post by:
I have created a datagrid control with textbox in a template column. I have injected the java scripts to this textbox in the data bind event. It works fine(with alert message!). But when I try to...
8
by: Sergei | last post by:
Hi, I am displaying modal dialog and passing values from the main form to the modal dialog and back. It works fine but if I used the following syntax on Page_Load(just for testing) in VB to...
3
by: vinoda2005 | last post by:
Hi friends, Here is my problem........ if i click on folder in C drive,a prompt box should be displayed asking username and password.if the entered details r valid,the folder should open...
9
by: ammupriya | last post by:
I require coding for adding text box and label box from the created button and then converting string value into integer from one text box to other.
4
by: Mangalaganesh Balasubramanian | last post by:
Hi, This is my requirement & i woudl arppreciate any assistance on this. I ahve a scanned form which has data entered by User. I want to have a web page which woudl display this scanned form...
4
by: karthiknd | last post by:
hi everyone , i need a script which copy folder from one system and has to be replaced in server folder which is in another system. This java script has to be called in asp.net...
9
by: Tuy Solang | last post by:
I download four scripts that are used to display Khmer PGN for Khmer Chess. It works fine with Netscape 7.1 on MS Millenium, but it gave me an error(Java Script console) with Netscape 8.1 on MS...
0
by: tosreejithp | last post by:
Hi, My first problem was i am not able to compiled a file from java script to java class.Now its clear and working fine..now i can convert a java script file to java class by Rhino Java Script...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.