By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,934 Members | 1,538 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,934 IT Pros & Developers. It's quick & easy.

document.all vs. document.getElementByID

P: n/a
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.
Dec 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a


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.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 12 '05 #2

P: n/a
Martin Honnen wrote:
Martin wrote:
But, if I modify it to use document.getElementByID, it generates a
syntax error.


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


Yep -

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

Dec 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.