Connecting Tech Pros Worldwide Forums | Help | Site Map

document.all vs. document.getElementByID

Martin
Guest
 
Posts: n/a
#1: Dec 12 '05
I have the following drop-down in one of my pages. Note the use of
document.all in calling the ShowView function. This seems to work OK.

<select id='mySelect' style='font-size:120%; width:150px;'
onchange=ShowView(document.all['mySelect'].options[document.all['mySelect'].selectedIndex].value)>
<option value='PICKLEVEL1'>Pick Level 1</option>
<option value='PICKLEVEL2'>Pick Level 2</option>
<option value='PICKLEVEL3'>Pick Level 3</option>
<option value='CHECKPACK'>Check Pack</option>
<option value='SHIPPING'>Shipping</option>
</select>

But, if I modify it to use document.getElementByID, it generates a
syntax error. I've Googled around a bit and found examples that seem
to indicate that this should work.

onchange=ShowView(document.getElementByID('mySelec t').options[document.getElementByID('mySelect').selectedIndex].value)>

Can someone tell me what I'm doing wrong here?

Thanks.

Martin Honnen
Guest
 
Posts: n/a
#2: Dec 12 '05

re: document.all vs. document.getElementByID




Martin wrote:

[color=blue]
> <select id='mySelect' style='font-size:120%; width:150px;'
> onchange=ShowView(document.all['mySelect'].options[document.all['mySelect'].selectedIndex].value)>[/color]

Simply use
<select onchange="ShowView(this.options[this.selectedIndex].value);"
[color=blue]
> But, if I modify it to use document.getElementByID, it generates a
> syntax error.[/color]

The method name is
document.getElementById
not document.getElementByID.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Tony
Guest
 
Posts: n/a
#3: Dec 12 '05

re: document.all vs. document.getElementByID


Martin Honnen wrote:[color=blue]
> Martin wrote:
>[color=green]
> > But, if I modify it to use document.getElementByID, it generates a
> > syntax error.[/color]
>
> The method name is
> document.getElementById
> not document.getElementByID.[/color]

Yep -

To the OP: Remember, JavaScript is a Case Sensitive language...

Closed Thread