473,597 Members | 2,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dynamic drop-down menu

hi,
so i'm creating a dynamic drop-down menu. the menu and the text show up
fine in IE but only the drop-down shows in Firefox without the menu
text. Below is the fxn code. help pls.

function DropDownHelper( menuArray, top, left, height)
{
var currItem = new String();
var item;
var idStr;
for(var i = 0; i < menuArray.lengt h; i++)
{
currItem = menuArray[i];
currItemArr = currItem.split( ";");

item = document.create Element("div");
idStr = "dropDownMenuId " + i;

ExistingMenuIte mIds[i] = idStr;

item.setAttribu te('id', idStr);
item.style.visi bility = "visible";
item.style.top = top;
item.style.font Family = "Arial";
item.style.font Size = "13pt";
item.style.colo r = "white";
item.style.font Weight = "bold";
item.style.posi tion = "absolute";
item.style.heig ht = height;
item.style.left = left;
item.style.widt h = "200px";
item.style.back groundColor = "red";
item.style.colo r = "white";
item.style.curs or = "hand";

item.innerHTML = "<p onclick = \"GoTo('" + currItemArr[1] + "')\">" +
currItemArr[0] + "</p>";
document.body.a ppendChild(item );
var newtop = GetIntFromPrope rty(top) + height;
top = newtop + "px";
}
}

Dec 11 '05 #1
3 3040

sc*******@gmail .com wrote:
hi,
so i'm creating a dynamic drop-down menu. the menu and the text show up
fine in IE but only the drop-down shows in Firefox without the menu
text. Below is the fxn code. help pls.
You have given us a function that you use. It would also be helpful to
see how you're calling this function, that is, the values that are
being passed in. Otherwise, the code that you've shown is perfectly
valid.

item.setAttribu te('id', idStr);
Just to be consistent with your portion of the code, you can also set
the id as follows:

item.id = idStr;
item.style.visi bility = "visible";
item.style.top = top;
item.style.font Family = "Arial";
item.style.font Size = "13pt";
item.style.colo r = "white";
item.style.font Weight = "bold";
item.style.posi tion = "absolute";
item.style.widt h = "200px";
item.style.back groundColor = "red";
item.style.colo r = "white";
item.style.curs or = "hand";
See all that above you wrote? You can easily put that into a
stylesheet and just refer to it by classname. It just saves you the
trouble of having to programmaticall y do it everytime. Plus it helps
separate presentation from logic.

item.className = "styleName" ;
item.innerHTML = "<p onclick = \"GoTo('" + currItemArr[1] + "')\">" +
currItemArr[0] + "</p>"; From the problem you described, this seems to be the place where you're

placing the text. You should check to see that there is indeed a value
in currItemArr[0]. Though you do say it works in IE, the code you've
given doesn't show how you're obtaining the value for menuArray. So it
may not work in FF like you said.

Dec 11 '05 #2
sc*******@gmail .com wrote:
so i'm creating a dynamic drop-down menu. the menu and the text show up
fine in IE but only the drop-down shows in Firefox without the menu
text. Below is the fxn code. help pls.

function DropDownHelper( menuArray, top, left, height)
{
var currItem = new String();
That is nonsense. JavaScript is not Java. You do not have to create
a String object in order to store string values in a variable.
var item;
var idStr;
for(var i = 0; i < menuArray.lengt h; i++)
for (var i = 0, len = menuArray.lengt h; i < len; i++)
{
currItem = menuArray[i];
Here you are overwriting the reference that you retrieved at the top.
currItemArr = currItem.split( ";");

item = document.create Element("div");
idStr = "dropDownMenuId " + i;

ExistingMenuIte mIds[i] = idStr;
Unless `ExistingMenuIt emIds' is intended to be a constructor function, its
identifier should be changed so that it's first letter is lowercase. That
is not a question of syntax, but of code style.
item.setAttribu te('id', idStr);
setAttribute() has too many flawed implementations to be considered a viable
DOM method on the Web. And it is not necessary, HTMLDivElements have an
`id' attribute that is exposed as an `id' property in DOM implementations .

item.id = idStr;
item.style.visi bility = "visible";
You should make sure that there is a `style' property before you try to
access properties that are properties of a supposed-to-be CSS2Properties
object.
item.style.top = top;
Whether that is viable depends on what you pass as value for `top'.
item.style.font Family = "Arial";
The font-family property value should be a comma-separated list of font
family names, ending with that of a _generic_ one, here "sans-serif".
item.style.font Size = "13pt";
`pt' is a unit suited for printouts, not for the screen. Use `%' or `em'.
[...]
item.style.heig ht = height;
item.style.left = left;
See above.
[...]
item.style.curs or = "hand";
"hand" is not a Valid value for the `cursor' property in CSS(2), and will
not work in Gecko-based browsers. The standards compliant equivalent for
this IE-proprietary value is `pointer'.
item.innerHTML = "<p onclick = \"GoTo('" + currItemArr[1] + "')\">" +
currItemArr[0] + "</p>";
`innerHTML' is a proprietary property that is supported in many browsers,
but not in all, and is still not standards compliant and therefore
error-prone.

Additionally, you are abusing the p(aragraph) element as control. Use an
`input' element instead; if you do not like it's style, use CSS to change
that.
document.body.a ppendChild(item );
Care to test methods before you call them?

<URL:http://pointedears.de/scripts/test/whatami>
var newtop = GetIntFromPrope rty(top) + height;
top = newtop + "px";


GetIntFromPrope rty(top) can probably be replaced easily by
parseInt(top, 10).

Are you aware that this menu will not work in client-side script or the
required DOM support is not present?

BTW: Do not use tabs but use spaces for indenting code, especially when
posting to the newsgroup. Every system and user agent has its own
interpretation of the Tab character.
HTH

PointedEars
Dec 11 '05 #3
sc*******@gmail .com wrote:
hi,
so i'm creating a dynamic drop-down menu. the menu and the text show up
fine in IE but only the drop-down shows in Firefox without the menu
text. Below is the fxn code. help pls.

function DropDownHelper( menuArray, top, left, height)
{
var currItem = new String();
Please don't use tabs in posted code. Use 2 or 4 spaces for indents and
wrap lines manually at about 70 characters.

There is no need for a string object, you can initialise it as a string
using:

var currItem = '';

var item;
var idStr;
for(var i = 0; i < menuArray.lengt h; i++)
{
currItem = menuArray[i];
currItemArr = currItem.split( ";");
This will create currItemArr as a global variable, is that neccessary?

var currItemArr = currItem.split( ";");


item = document.create Element("div");
You should test for support before using DOM features:

if (document.creat eElement) {
document.create Element('div');
// ...

idStr = "dropDownMenuId " + i;

ExistingMenuIte mIds[i] = idStr;
Where was ExistingMenuIte mIds declared? Is it a global variable?


item.setAttribu te('id', idStr);
Simpler to use:

item.id = idStr;

item.style.visi bility = "visible";
You should test for support for style objects, using a class is much
simpler. Div's are visibile by defalut, there is not need to set them
as visible unless you have previously set it to hidden.

if (item.style){
item.style.visi bility = 'visible';

item.style.top = top;
Where was 'top' defined? What is its value?

item.style.font Family = "Arial";
item.style.font Size = "13pt";
Font sizes should be set using proportional units - em, en, etc.

item.style.colo r = "white";
item.style.font Weight = "bold";
item.style.posi tion = "absolute";
item.style.heig ht = height;
item.style.left = left;
Where are 'height' and 'left' defined?

item.style.widt h = "200px";
item.style.back groundColor = "red";
item.style.colo r = "white";
That's the second time you've set the color attribute.

item.style.curs or = "hand";
'hand' is not a valid CSS value for the the cursor, use 'pointer'
(though I think some older versions of IE may require 'hand').


item.innerHTML = "<p onclick = \"GoTo('" + currItemArr[1] + "')\">" +
currItemArr[0] + "</p>";
You've used DOM for everything else, why not here too? It's a much
safer way of adding the onclick:

var oP = document.create Element('p');
oP.appendChild( document.create TextNode(currIt emArr[0]));
oP.onclick = function(){GoTo (currItemArr[1])};



document.body.a ppendChild(item );
var newtop = GetIntFromPrope rty(top) + height;
What does 'GetIntFromProp erty()' do? Presumably it trims 'px' from the
value of 'top'. Why not set top as an integer and concatenate 'px' when
you set the style property?

Where you declare your other variables, add:

var newtop = 0;
Presumably you want to set the div's 'top' attribute as:

item.style.top = newtop + 'px';
And here:

newtop += top;

top = newtop + "px";
}
}


I can't test the code because you haven't given sufficient information.
There are thousands of drop-down menus out there, many based on CSS
that use very little JavaScript, some use none. Quite a few are offered
completely unencumbered.

Why not just use one of those? There are quite a few offered here:

<URL:http://www.alistapart. com/topics/code/css/>

--
Rob
Dec 11 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2390
by: Guinness Mann | last post by:
When you guys talk about "dynamic SQL," to what exactly are you referring? Is dynamic SQL anything that isn't a stored procedure? Specifically, I use ASP.NET to communicate with my SQL Server 2000, using an SqlConnection object to open the database and an SqlCommand object to transfer my SQL text to the database. Is this the "dynamic SQL" that is such a bad thing? What is my alternative? Wait until after my program is working and...
31
3667
by: NickName | last post by:
/* goal: dynamic evaluation of table row platform: sql 2000 */ use northwind; declare @tbl sysname set @tbl = 'customers' EXEC('select count(*) from ' +@tbl)
7
8472
by: Yaro | last post by:
Hello Is it possible using dynamic SQL in UDF? In Sybase below example work but in DB2 UDB 8.1.3 I get error: "SQL0104N Unexpected element "EXECUTE IMMEDIATE" found....." CREATE FUNCTION DropTable(p_TableName VARCHAR(30) ) RETURNS VARCHAR(50) LANGUAGE SQL BEGIN ATOMIC
3
6816
by: MikeY | last post by:
Hi Everyone, I am working in C#, windows forms.My question is this. All my button dynamic controls properties are present and accounted for except for the"FlatStyle" properties. I can't seem to figure out, if there is a way of using polymorphic way (if that is a word) of doing this particular property. A sample of my code is as follows: DynamicControls.ButtonControl(this,btnSearchByName, new Point(5, 75), new Size(95, 20),...
1
1274
by: jm | last post by:
I am using (trying) dynamic properties to store a database connection. However, I don't have a connection object on the form. I just do a OdbcConnection in my code. So I can't use the VS IDE to set up my Dynamic Properties. Can I still use Dynamic Properties? Or am I required to set up objects on the form first and use the IDE to create the appropriate settings and .xml file? Thanks.
7
3382
by: serge | last post by:
How can I run a single SP by asking multiple sales question either by using the logical operator AND for all the questions; or using the logical operator OR for all the questions. So it's always either AND or OR but never mixed together. We can use Northwind database for my question, it is very similar to the structure of the problem on the database I am working on. IF(SELECT OBJECT_ID('REPORT')) IS NOT NULL DROP TABLE REPORT_SELECTION
2
1802
WhiteRider
by: WhiteRider | last post by:
Hello, I am having some trouble with a guy that has a dynamic IP address. I noticed he is trying to brute-force my SSH account so I used IPtables to drop all incoming packets. The exact command was iptables -I INPUT -s 84.74.xxx.xxx -j DROP where x is the rest of his IP. This automatically blocked him. No more activity came from his IP, which is exactly what I want. However 5 minutes later he came back this time with a slightly different...
1
4646
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by pressing Remove button the selecetd row will be removed. I used viewstate to keep my value for postback, I want by changing selectedvalue of...
0
3488
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by...
0
7970
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7887
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8274
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8381
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8036
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
3886
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2404
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1494
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1241
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.