document.all vs. document.getElementByID

M

Martin

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('mySelect').options[document.getElementByID('mySelect').selectedIndex].value)>

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

Thanks.
 
M

Martin Honnen

Martin wrote:

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

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

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

Lee

Martin said:
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('mySelect').options[document.getElementByID('mySelect').selectedIndex].value)>

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

<select id='mySelect'
style='font-size:120%; width:150px;'
onchange="ShowView(this.options[this.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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,058
Members
48,769
Latest member
Clifft

Latest Threads

Top