View Full Version : JS multiple menu problem - might be CSS or function

08-24-2007, 08:38 PM
I've been racking my brain on this one. It seems like it should work. I don't know where it's hanging up.

I'm having what I believe is a Javascript conflict between two functions. This has caused one of my two forms (a jump menu with CSS formatting) not to function properly.

Here is the problem:

I have two drop down menu forms.

The first has 3 pieces:
- a text box for user entry
- a drop down to select a location
- and submit button

The first drop down menu works fine. When you click on the submit button, you are redirected to the results.php page and that works fine.

The second form/menu seems to hang.

It's a simple jump menu with the some of the same formatting as above. The drop down portion works fine, it just doesn't jump anywhere when you make a selection. Note: it also is formatted via the javascript and CSS. And the jump menu works by itself unformatted on it's own.

To make it simpler, I removed all of the extra code and posted the menus on a temporary staging server:

There is a url which has both menus:


Here are the Javascript and CSS files:


you can disregard some of the styles, as they are for other portions not relevant to the menu.

Any help would be greatly appreciated!!

Thanks so much!! - VN

08-25-2007, 12:18 AM
The list is masking the onchange event.

For accessibility, a submit button or image as in the first form for non-js clients might be something to consider.

You may be able to fire the onchange from the list/options handling, but, since the selected option in the second form amounts to a link, why not just use the list instead of a form.

08-25-2007, 12:35 AM
the fake select code is not complete and has much redundant code but to get the same functionality as the original select

function selectReplacement(obj) {
obj.className += ' replaced';
var ul = document.createElement('ul');
ul.className = 'selectReplacement';
var opts = obj.options;
for (var i=0; i<opts.length; i++) {
var selectedOpt;
if (opts[i].selected) {
selectedOpt = i;
} else {
selectedOpt = 0;
for (var i=0; i<opts.length; i++) {
var li = document.createElement('li');
var txt = document.createTextNode(opts[i].text);
li.selIndex = opts[i].index;
li.selectID = obj.id;
li.onclick = function() {
if (i == selectedOpt) {
li.className = 'selected';
li.onclick = function() {
this.parentNode.className += ' selectOpen';
this.onclick = function() {
if (window.attachEvent) {
li.onmouseover = function() {
this.className += ' hover';
li.onmouseout = function() {
this.className =
this.className.replace(new RegExp(" hover\\b"), '');

function selectMe(obj) {
var lis = obj.parentNode.getElementsByTagName('li');
for (var i=0; i<lis.length; i++) {
if (lis[i] != obj) {
lis[i].onclick = function() {
} else {
setVal(obj.selectID, obj.selIndex);
obj.parentNode.className =
obj.parentNode.className.replace(new RegExp(" selectOpen\\b"), '');
obj.onclick = function() {
obj.parentNode.className += ' selectOpen';
this.onclick = function() {

08-31-2007, 05:02 PM
Thanks so much! Super helpful!! What a great forum!!

Here is another way via adding the "if line" on the bottom

function setVal(objID, selIndex) {
var obj = document.getElementById(objID);
obj.selectedIndex = selIndex;
if (obj.onchange) obj.onchange();

08-31-2007, 07:01 PM
as this function is not currently used plaese explain the objective.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum