Solved

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

Posted on 2006-07-20
8
246 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
  • 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

810 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