at present the checkbox i have gets checked either by mouseclick or by tab button. instead of tab button i want the checkbox t obe checked by spacebar during runtime.
is it possible how?
| SitePoint Sponsor |




at present the checkbox i have gets checked either by mouseclick or by tab button. instead of tab button i want the checkbox t obe checked by spacebar during runtime.
is it possible how?
If possible, would have to be javascript, but seems like a bit of an overkill to me
I agree with NightStalker, it can be overkill for most people, but if you agree with me that its a huge oversight by browsers that you can't use the keyboard to select checkboxes then the following code might help.
I have used standard javascript code, but if your using some sort of javascript framework (jQuery, YUI, etc) then use them instead.
Cross browser code to get KeyCode (IE 5.5+, FF 2+, Opera 9+)
Either use ASP.NETCode:function KeyCode() { if(typeof window.event!='undefined') { return window.event.keyCode; } else { if(typeof event!='undefined') { if(event.keyCode!=0) { return event.keyCode; } else { return event.which; } } else { return 0; } } }
or Attach your own function using javascript.Code:CheckBox1.Attributes["onkeydown"] = "var k=KeyCode();if(k==32){document.getElementById('" + CheckBox1.ClientID + "').click();}"
Hope this helps
You can use space to select in Firefox, dnt use any other browser, so wouldnt no if you can or not in those. I just think its an overkill as there is a bit of JS on the page, and uses will likely not use it as they are used to just clicking








you where right , spacebar toggels the check and uncheck and tab shifts the focus frm one control to another
but for the checkbox list instead of tab control shifting the focus i want it to be done using down arrow key is it possible




it can certainly be done, but I don't think it's something you can do directly with the checkbox list control. You would have to write some custom javascript (at least that's what I would do), to capture the keypress event and move focus on the arrow key presses.
a search or question in the javascript forum would probably be the way to go.
I've never added onkeypress attribute to a checkboxlist in .NET so I have no idea what may happen... but if it's not what you wanted - then keep in mind that your custom javascript will need to effect the HTML that gets spit out by .NET.
My hunch is that you'll be better off NOT trying to interwine this with your asp.NET code.
But I been wrong before.





This is not a common user case scenario. Highly not recommended.
You can catch the key events on server side as well, if you need. Using it with AJAX would hide the postback.
Why purposely confuse the end user by changing the browser's expected behavior?




I HAVE READ ALL MSGS BUT NOT GETTING THE DESIRED SOLUTION
I HAVE A ASPX PAGE WITH FEW CONTROLS
LIKE TEXTBOXES, DROP DOWN BOXES . ALONG WITH IT I HAVE A CHECKBOX IN A DIV WHICH HAS A SCROLL BAR.i have set the taborder
when i load the page my tab index is on first textbox
when i press tab it goes to next control and so on . when it comes to checkbox opuplated with items frm database(suppose i have 50 checkbox in the div) , when my tab comes to the first checkbox , i have to press tab 50 times to come out of the control and go to next control outside the div
so to avoid it i wanted the tab to shift between the controls and for checkbox ina div i wanted up/down arrow key .
Javascript Would Be Solution, Post There
Bookmarks