Hi,
I am trying to get javascript to write the following code into my page, however it will not show -
<ul class="basictab">
-
<li class="selected"><a href="my menu test.htm">Home</a></li>
-
<li><a href="slashdot_menu.html">Slashdot Menu</a></li>
-
<li><a href="block_menu.htm">Block Menu</a></li>
-
<li><a href="shadow_test.htm">Shadow Test</a></li>
-
</ul>
-
This is the javascript that I have have tried -
<!--
-
function insertmenu(text){
-
var object = text.className
-
object.className = "selected";
-
}
-
function writeJS(){
-
var str='';
-
str+='<ul class="basictab">';
-
str+='<li name="home" class=""><a href="my menu test.htm">Home<\/a><\/li>';
-
str+='<li name="slashdot" class=""><a href="slashdot_menu.html">Slashdot Menu<\/a><\/li>';
-
str+='<\/ul>
-
document.write(str);
-
}
-
//-->
-
The insertmenu function needs to be able to change the class of the chosen list item to selected
Could you please help
Thnx in advance
12 2029
What calls these methods, and when? If you call document.write() after the page has loaded, what you are doing is over writing the entire page with that HTML.
You may want to try setting .innerHTML to add code. -
-
var someElement = document.getElementById('someTagID');
-
someElement.innerHTML = '<<YOUR HTML HERE>>'
-
-
Hi,
The insertmenu function needs to be able to change the class of the chosen list item to selected
So are you saying this currently does not work? The code looks correct. What event is it triggering on?
it needs to write it onload along with all of the other html as it is for a horizontal menu
p.s. I have the same script without the insertmenu function on some of my other pages only without the list and that works ok as it is just working with hyperlinks
You didnt answer any of my questions. There is not much we can tell you without at lest some details. How specificly is this being called. To avoid confustion it is easiest to provide the code that calls them. (Inside code tags.)
Are both functions being called at the same time? What happens when the are called? Error messages of any kind?
If it works on other pages without the insert function, have you tried removing the insert function on this page to see if it works then? Is the object that is passed to the insert function being called before the tag is on the page? i.e. Is it called inline, and above it in the code?
this is the current coding inside my page -
<script language="Javascript" src="js/linktop.js">
-
<!--
-
writeJS();
-
insertmenu('home');
-
//-->
-
</script>
-
Other html
-
and I have tried it without the insert function yet it still doesn't work, it just doesn't want to write out the list
When you use the src attribute of the script tag, you can't add some more JavaScript within the script tags. Close them and start new ones for the inline code: -
<script type="text/javascript" src="js/linktop.js"></script>
-
<script type="text/javascript">
-
writeJS();
-
insertmenu('home');
-
</script>
it's working gr8 now thnx for all of ur help
last post was incorrect I had forgotten to remove something which made me think that it was working sorry, it is still not working and it comes up with an error "'undefined' is null or not an object" on line 4 of the script
last post was incorrect I had forgotten to remove something which made me think that it was working sorry, it is still not working and it comes up with an error "'undefined' is null or not an object" on line 4 of the script
I've got a code that does this at my house somewhere, i'll post it later.
Thanks, Death
last post was incorrect I had forgotten to remove something which made me think that it was working sorry, it is still not working and it comes up with an error "'undefined' is null or not an object" on line 4 of the script
You're passing a string to the insertmenu function, not an object. You need to get the className property of the li element, not a string. Give the li elements ids and then pass the id as the argument. Then use document.getElementById(passed_id) to get hold of the element.
Hello!
Yes, as acoder suggested, you should use the id property of the element and use document.getElementById() to select that element, instead of name tag. But this can also be done using document.getElementsByName which returns an array of elements(in our case we will have only value in the array). So, your function should look like this: -
function insertmenu(text){
-
var object = document.getElementsByName(text);
-
object[0].className = "selected";
-
}
-
My complete test page is this: - <html>
-
<head>
-
<script type="text/javascript">
-
function insertmenu_(text){
-
var object = text.className;
-
object.className = "selected";
-
}
-
function insertmenu(text){
-
var object = document.getElementsByName(text);
-
object[0].className = "selected";
-
}
-
-
function writeJS(){
-
var str='';
-
str+='<ul class="basictab">';
-
str+='<li name="home" class=""><a href="my menu test.htm">Home<\/a><\/li>';
-
str+='<li name="slashdot" class=""><a href="slashdot_menu.html">Slashdot Menu<\/a><\/li>';
-
str+='<\/ul>';
-
document.write(str);
-
}
-
writeJS();
-
insertmenu('home');
-
</script>
-
</head>
-
<body>
-
</body>
-
</html>
Hope this answers your question.
Dan
yes this is working great now thanks for all of your help
Glad it helped. Post again if you have any more questions.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: techy techno |
last post by:
Hii
Just wanted to know how can I decorate my texboxes and Listmenu which is
called from a JS file using the following code below:
document.write("<SELECT NAME='cur2' ONCHANGE='cconv1();'>");...
|
by: Brett Baisley |
last post by:
Hello
I have a block of html code that I want to run by calling a javascript
function to print it. Its basically a table with menu items in it that is
the same for many pages, and instead of...
|
by: Eli |
last post by:
I've got a script that I'm trying to debug which uses document.write()
to place HTML within a page. In both IE6 and Firefox when I view
source, I see only the script itself and not any HTML as...
|
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,...
|
by: bissatch |
last post by:
Hi,
I am trying to use JavaScript to write a table column on a web page.
The code is as follows:
<html>
<head>
<script>
function displaycount() {
|
by: Tony |
last post by:
Is it me, or is document.write just about the most abused js function?
Maybe, like goto, js would be better without it?
Is there any good reason to use it? Because I'm having a hard time
seeing...
|
by: anupamaavadutha |
last post by:
hi all,
iam new to javascript. i have problem calling javascript functions.iam designing a calender page.here is my code.
<%@ page...
|
by: Mateusz Viste |
last post by:
Hi,
I am trying make some multimedia files playable from my website. So far, I
am able to generate dynamically a new page containing the right <embed>
section. However, when I load my script, it...
|
by: celeroSolutions |
last post by:
This code works in my site in IE, but not in FireFox, and I'm stuck as to why! Any ideas? (The image paths are correct, I've tested these.)
<script language="javascript" type="text/javascript">...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
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...
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |