Solved

can't blur the focus on a <select> drop-down list

Posted on 2006-07-20
8
248 Views
Last Modified: 2008-01-09
Hello-

I need to control the appearance of a disabled drop-down list, but I'm not having any luck creating the read-only effect.  Here is the code I generate (via my asp.net 1.1 app), and at least in IE I can still change the selection:

<select name="job:rep" id="job_rep" onfocus="this.blur();">
            <option value="65">Adam Parrish</option>
            <option value="18">Alan Goldstein</option>
            <option value="22">Anna Dominguez</option>
            <option selected="selected" value="32">Greg White</option>
</select>

I have also tried the following, with the same result:

<select name="job:rep" id="job_rep" onfocus="javascript:this.blur();">
<select name="job:rep" id="job_rep" onfocus="function preventFocus(e) { this.blur(); }">

Thanks for any help-

Mike
0
Comment
Question by:ottenm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 26

Accepted Solution

by:
DireOrbAnt earned 250 total points
ID: 17147612
I suppose you could focus the next element (or previous) as in:
<input type="text">
<select name="job:rep" id="job_rep" onfocus="document.getElementById('AfterSelect').focus()">
          <option value="65">Adam Parrish</option>
          <option value="18">Alan Goldstein</option>
          <option value="22">Anna Dominguez</option>
          <option selected="selected" value="32">Greg White</option>
</select>
<input id="AfterSelect" type="text">
0
 

Author Comment

by:ottenm
ID: 17147688
Better, but a bit awkward.  When I click on the drop-down, it starts to open and display the list, and then all of a sudden closes and moves the focus the the next element.

A fix though, so thanks!
0
 

Author Comment

by:ottenm
ID: 17147878
Wups, you can still edit the drop down.  If you double-click instead of single click, the second click catches the dropdown and then you can drag up/down through the list.  When you let go, the control has the focus and the new value is selected.

Should I start a new thread with this since I already awarded the points?
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 26

Expert Comment

by:DireOrbAnt
ID: 17148467
Why don't you use this:
<select name="job:rep" id="job_rep" DISABLED>
0
 

Author Comment

by:ottenm
ID: 17148484
No control over the appearance (browser chooses foreground/background colors).
0
 
LVL 26

Expert Comment

by:DireOrbAnt
ID: 17148524
<input type="text">
<select name="job:rep" id="job_rep" onfocus="document.getElementById('AfterSelect').focus()" onchange="this.selectedIndex = PreviouslySelectedItem">
          <option value="65">Adam Parrish</option>
          <option value="18">Alan Goldstein</option>
          <option value="22">Anna Dominguez</option>
          <option selected="selected" value="32">Greg White</option>
</select>
<input id="AfterSelect" type="text">

<SCRIPT TYPE="text/javascript">
var PreviouslySelectedItem = document.getElementById('job_rep').selectedIndex;
</SCRIPT>

Make sure the script block goes into a BODY onload.
0
 

Author Comment

by:ottenm
ID: 17148552
I'll buy that!  Thanks DireOrbAnt!
0
 
LVL 26

Expert Comment

by:DireOrbAnt
ID: 17148646
Sold!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question