473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Prevent select's dropdown list from being rendered

Hi All,

I want to write a select control and use a Javascript function to
handle all click events on the control. Under certain circumstances I
also wish to prevent the dropdown's list from being rendered.

Here is a sample showing what I am _unsuccessfully_ trying to do. :-/

<html>
<head>
<title>Test</title>
<script type="text/javascript">
function selectOnclick(e) {
// e gives access to the event in all browser
if (!e) var e = window.event;
if (e) { e.cancelBubble = true; }
return false;
}
</script>
</head><body>
<form name="test">
<select name="select" onmousedown="selectOnclick();">
<option value="one">one</option>
</select>
</form>
<script type="text/javascript">
document.test.select.onmousedown = selectOnclick;
</script>
</body>
</html>

Any advice would be most appreciated!

Rob
:)
Jul 23 '05 #1
1 6336
re********@optushome.com.au wrote:
Hi All,

I want to write a select control and use a Javascript function to
handle all click events on the control. Under certain circumstances I
also wish to prevent the dropdown's list from being rendered.
I don't think you can do this. The only thing I can think of is to
disable/re-enable the control, but you have to re-enable it from a
separate function using setTimeout().

I've added a few comments on your code too.

Here is a sample showing what I am _unsuccessfully_ trying to do. :-/

Please don't use tabs in code, indent by 2 or 4 spaces and replace
tabs with spaces. Then manually wrap at say 70 characters.
<html>
<head>
<title>Test</title>
<script type="text/javascript">
function selectOnclick(e) {
// e gives access to the event in all browser
if (!e) var e = window.event;
e = e || window.event;

will do just as well. But you haven't passed event from the
onmousedown anyway.
if (e) { e.cancelBubble = true; }
This will only cancel the event in IE, it has no effect in other
browsers. To add canceling for other browsers, add:

e.cancelBubble = true;
if (e.stopPropagation) {
e.stopPropagation();
}
return false;
}
</script>
</head><body>
<form name="test">
<select name="select" onmousedown="selectOnclick();">
Need to pass event to the function, disable, etc.:

<select name="select" onmousedown="
this.disabled = true;
selectOnclick(event);
alert('hi');
setTimeout('enableThis()',10);
">

If you comment out the alert, you won't even see the select
disable/renable, it just refuses to drop down the option.
<option value="one">one</option>
</select>
</form>
<script type="text/javascript">
document.test.select.onmousedown = selectOnclick;
Why add the function a second time? This will overwrite the
onmousedown on the element so remove it. I put my re-enable function
here but you could add it elsewhere:

function enableThis(){
document.forms['test'].elements['select'].disabled = false;
}
</script>


Having done the above, you don't need to cancel the event if the
purpose was only to stop the drop-down.

I'm not sure doing this at all is a good idea, playing with the user
interface just annoys users. Is there no other way to do what you
are trying to achieve?

--
Rob
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rod Early | last post by:
I need to know when the select element's dropdown list is opened (as when the user clicks on the arrow or does ALT-downarrow from the keyboard). Similarly, I need to known when the dropdown list...
5
by: Ganco | last post by:
We have a dropdown combobox, where some of the text is wider than the textarea. I cannot set the width of the SELECT any higher due to design restrictions on the company website. When clicking...
1
by: nicholas | last post by:
Hi, If on an asp.net page the user has just selected a value in a dropdownlist and scrolls with the wheel of his mouse, the selected value of the dropdownlist will change. How could I avoid...
3
by: =?Utf-8?B?SmF2YW1hbjU5?= | last post by:
I have an ASP.NET example which programmatically builds a drop down list. public class WebForm1 : System.Web.UI.Page { protected System.Web.UI.WebControls.DropDownList ddlCategories; public...
4
by: =?Utf-8?B?c2lMdmVy?= | last post by:
Hhi, I'm working on an asp .net project that have small side panel which 'disallow' long SELECT/dropdown list.. So i could not force them to a certain that shows my longest option, which now...
0
by: josephkorn | last post by:
Hi all. I have a problem in my website in trying to prevent a user from double submitting the form. I am calling a subroutine from my page_load event that passes in the commandbutton that I want...
1
by: =?Utf-8?B?U3Rvcm1icmluZ2Vy?= | last post by:
I have an UpdatePanel with a dropdown list that I can't seem to get to update. It has a hidden button which I click from javascript added to the page when another update panel is updated. Triggers...
1
by: prathna | last post by:
Hi I have this following code <script> function displayFields() { document.getElementById('Label12').style.display = 'none'; document.getElementById('Label13').style.display =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.