Making selectedIndex code cross-browser compliant

Hello.
I have a small bit of JS I'm having trouble with.  It works perfect in firefox 1.5.x but I'm having trouble with IE6+.  I'm VERY new to learning JS so bear with me. The error is Error: 'document.all.other.style' is null or not an object.  I've tried a few things with no luck.

              <select name="type_reg" class="inputpad" onchange="if(this.selectedIndex >= '4')document.all.other.style.display = 'block';else document.all.other.style.display = 'none'">
          <option value=''></option>            
          <option value='Supervisor'>Supervisor</option>
          <option value='State Agency'>State Agency</option>
          <option value='Federal Agency'>Federal Agency</option>
          <option value='Other'>Other</option>
          <option value='Guest'>Guest Name</option>
        </select>
        <br />
            <div id="other" style="display:none">
        Other/Guest Name:<br />
        <input name="other" type="text" class="inputpad" size="25">
            </div>
grizumAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

devicCommented:
try this:
===========
<select name="type_reg" class="inputpad"
      onchange="document.getElementById('other').style.display=this.selectedIndex>=4?'block':'none'">
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KennyTMCommented:
hi.

As I know, document.all, as well as document.getElementById(), gets element according to the ID only, not the name. Hence you should replace the last but second line with

        <input name="other" type="text" class="inputpad" size="25" id="other">

Hope this helps.
0
smaccariCommented:
To be cross browser compatible, use document.getElementById:

<select name="type_reg" class="inputpad" onchange="if(this.selectedIndex >= '4')document.getElementById('other').style.display = 'block';else document.getElementById('other').style.display = 'none'">
          <option value=''></option>          
          <option value='Supervisor'>Supervisor</option>
          <option value='State Agency'>State Agency</option>
          <option value='Federal Agency'>Federal Agency</option>
          <option value='Other'>Other</option>
          <option value='Guest'>Guest Name</option>
        </select>
        <br />
          <div id="other" style="display:none">
        Other/Guest Name:<br />
        <input name="other" type="text" class="inputpad" size="25">
          </div>

This works on both FF and IE.
0
grizumAuthor Commented:
Thanks for the replies!

I'm in the process of replacing a hard drive in our webserver -- I will give this a try as soon as I'm done :)
0
grizumAuthor Commented:
Several good answers.  The reason I put the ID in the DIV is to hide the text above the input box.

Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.