Log in

View Full Version : Javascript for select box help



stompkins
06-16-2006, 07:20 PM
Hi all,
What I am trying to do is when the user uses the select box and slecects the option of Add/Delete it pops up a div.

As you can see in the code it works. What is bothering me is that when I select a regular option (i.e Architectural or Mechanical) it produces a javascript error. Can any one help me out so it does not show this error?

** note I am only seeing it say it has an error in IE**

sample of what I am doing is located here

http://www.stevetompkins.com/dropdown.html

Thanks in advance

Twey
06-16-2006, 07:31 PM
Move the code in the <select>'s onchange event to the <option>'s onclick event.

stompkins
06-16-2006, 08:44 PM
so you are saying take


onchange="hideAll(); changeDiv(this.options[this.selectedIndex].value,'block');"

and change it to


onclick="hideAll(); changeDiv(this.options[this.selectedIndex].value,'block');"

and move it from the select tag down to the option tag?

I tried that with no success =(

Twey
06-16-2006, 09:15 PM
You haven't done it on your demo page.

stompkins
06-16-2006, 09:25 PM
sorry about that I just made the change local. if you visit it now it is updarted with your suggestion.

Thanks

Twey
06-16-2006, 09:46 PM
Revert your code, and let's just add some basic sanity checking:
function changeDiv(the_div,the_change)
{
if(!document.getElementById(the_div)) return;
document.getElementById(the_div).style.display=the_change;
}

stompkins
06-17-2006, 11:32 AM
Awesome! I think that did the trick. I really appreciatet your help.

Thanks!

djr33
06-17-2006, 08:53 PM
Just to let you know... that doesn't work in Safari. I'm not too surprised, though. It's JS implementation is different than FF/IE.

Also, I'd recommend having a "Choose one below" or something as the first item in the select menu, so that you don't have Architectural already up, but no div, causing confusion.

EDIT: Um.... this doesn't seem to work in FF either.
...or IE (5/mac).

Twey
06-17-2006, 09:01 PM
Basically, doesn't work? :p
It's JS implementation is different than FF/IE.It uses KHTML, insofar as I'm aware, so it's most similar to Konqueror. However, it tends to be several versions of the component behind Konqueror.

djr33
06-17-2006, 09:03 PM
Well, I'm not talking about html. The html doesn't behave that differently... not in a noticably bad way, really.
The javascript just varies from other browsers.
Perhaps the javascript is part of the implemenation of KHTML; I wouldn't know.

Twey
06-17-2006, 09:07 PM
Perhaps the javascript is part of the implemenation of KHTML; I wouldn't know.It is. Insofar as I'm aware, anyway.

djr33
06-17-2006, 09:18 PM
Ah, ok then.

I still don't understand why Apple doesn't get that they're doing something weird. With only 2% of webusers with macs, I don't see why they think anyone will make special efforts to be compatible with them.

Plus, it's just lack of functionality... not varied functionality. There's nothing I've seen that is Safari specific that can't be done in IE/FF that is a good thing.... just some stuff not working in Safari.

Twey
06-17-2006, 09:26 PM
There's nothing I've seen that is Safari specific that can't be done in IE/FF that is a good thing.... just some stuff not working in Safari.But the same could be said of IE vs FX :) I'm sure Apple have their reasons. And don't forget that they were the first ones to implement a canvas.

djr33
06-18-2006, 10:12 AM
Apple still ships with a single click mouse. Ouch.
Someone please tell me the reasoning there.
Plus, they've recoded their operating system, with the biggest improvement clearly just being that there is now multi-button functionality... not just right click, but scrolling as well.
Yet... they send you a very fancy, shiny, laser, see-through yet single click mouse.

But, true about the IE thing.
At least IE has a few things like VML that aren't offered in other browsers. Not neccessarily good, but at least it's something of an attempt to add more content, whereas safari makes no particular attempts to add anything, but just doesn't support a bunch.

Twey
06-18-2006, 10:24 AM
I repeat: Safari was the first browser to implement canvas.

djr33
06-18-2006, 10:29 AM
What's canvas?


EDIT: Googled. Hmm... that's cool. Isn't it similar to VML?
Why can't they just agree...

Twey
06-18-2006, 10:49 AM
Why can't they just agree...Because any compatibility that might fail to hinder the opposition is the #1 sin of the Microsoft religion :)
EDIT: Googled. Hmm... that's cool. Isn't it similar to VML?It's quite different... canvas uses Javascript, while VML is an XML-based language. I think that makes VML less flexible, but I wouldn't swear to it.

djr33
06-18-2006, 10:59 AM
Similar in purpose though. Didn't look too closely at the codes for them.

stompkins
06-19-2006, 02:00 PM
Also, I'd recommend having a "Choose one below" or something as the first item in the select menu, so that you don't have Architectural already up, but no div, causing confusion.

EDIT: Um.... this doesn't seem to work in FF either.
...or IE (5/mac).

Hi , I appreciate your help. The "Choose below" thing is a great idea. As for Mac I am not worried about that for now. It will be in a app for IE