-
Script works in Mozilla but not in IE
Hi,
I'm currently developing a questionare web page for showing questions and handling response. The page will have 7 radiobuttons on a scale 1-7 for user response.
I want the user to be able to use the keyboard when answering by pressing the keys 1-7, or using the arrow keys. When the 1-7 key is pressed the corresponding radiobutton will be focused and checked. When the arrowkeys is used the next or previous radiobutton will be focused and checked.
The javascript is working fine in Mozilla, but when i try it in IE it fails. The keys 1-7 works in IE, but the arrowkeys dont work as expected.
Any suggestions?
Here is the javascript code:
<script language="javascript">
var thisfocus = -1;
function handlePress(e, totElements) {
var whichCode = (window.Event) ? e.which : e.keyCode;
if (String(whichCode)=="9"){
event.keyCode=0;
e.returnValue=false;
} else if(String(whichCode)=="49"){
if(0>=totElements){
}else{
thisfocus = 0;
setFocus(thisfocus);
setChecked(thisfocus);
}
}else if (String(whichCode)=="50"){
if(1>=totElements){
}else{
thisfocus = 1;
setFocus(thisfocus);
setChecked(thisfocus);
}
}else if (String(whichCode)=="51"){
if(2>=totElements){
}else{
thisfocus = 2;
setFocus(thisfocus);
setChecked(thisfocus);
}
}else if (String(whichCode)=="52"){
if(3>=totElements){
}else{
thisfocus = 3;
setFocus(thisfocus);
setChecked(thisfocus);
}
}else if (String(whichCode)=="53"){
if(4>=totElements){
}else{
thisfocus = 4;
setFocus(thisfocus);
setChecked(thisfocus);
}
}else if (String(whichCode)=="54"){
if(5>=totElements){
}else{
thisfocus = 5;
setFocus(thisfocus);
setChecked(thisfocus);
}
}else if (String(whichCode)=="55"){
if(6>=totElements){
}else{
thisfocus = 6;
setFocus(thisfocus);
setChecked(thisfocus);
}
}else if (String(whichCode)=="56"){
if(7>=totElements){
}else{
thisfocus = 7;
setFocus(thisfocus);
setChecked(thisfocus);
}
}else if (String(whichCode)=="57"){
if(8>=totElements){
}else{
thisfocus = 8;
setFocus(thisfocus);
setChecked(thisfocus);
}
}else if (String(whichCode)=="97"){
if(0>=totElements){
}else{
thisfocus = 0;
setFocus(thisfocus);
setChecked(thisfocus);
}
}else if (String(whichCode)=="98"){
if(1>=totElements){
}else{
thisfocus = 1;
setFocus(thisfocus);
setChecked(thisfocus);
}
}else if (String(whichCode)=="99"){
if(2>=totElements){
}else{
thisfocus = 2;
setFocus(thisfocus);
setChecked(thisfocus);
}
}else if (String(whichCode)=="100"){
if(3>=totElements){
}else{
thisfocus = 3;
setFocus(thisfocus);
setChecked(thisfocus);
}
}else if (String(whichCode)=="101"){
if(4>=totElements){
}else{
thisfocus = 4;
setFocus(thisfocus);
setChecked(thisfocus);
}
}else if (String(whichCode)=="102"){
if(5>=totElements){
}else{
thisfocus = 5;
setFocus(thisfocus);
setChecked(thisfocus);
}
}else if (String(whichCode)=="103"){
if(6>=totElements){
}else{
thisfocus = 6;
setFocus(thisfocus);
setChecked(thisfocus);
}
}else if (String(whichCode)=="104"){
if(7>=totElements){
}else{
thisfocus = 7;
setFocus(thisfocus);
setChecked(thisfocus);
}
}else if (String(whichCode)=="105"){
if(8>=totElements){
}else{
thisfocus = 8;
setFocus(thisfocus);
setChecked(thisfocus);
}
}else if (String(whichCode)=="37"){
alert(thisfocus);
thisfocus = thisfocus-1;
alert(thisfocus);
if(thisfocus<0) thisfocus = 0;
setFocus(thisfocus);
setChecked(thisfocus);
}else if (String(whichCode)=="38"){
alert(thisfocus);
thisfocus = thisfocus-1;
alert(thisfocus);
if(thisfocus<0) thisfocus = 0;
setFocus(thisfocus);
setChecked(thisfocus);
}else if (String(whichCode)=="39"){
alert(thisfocus);
thisfocus=thisfocus+1;
alert(thisfocus);
if(thisfocus>totElements-1) thisfocus = totElements-1;
setFocus(thisfocus);
setChecked(thisfocus);
}else if (String(whichCode)=="40"){
alert(thisfocus);
thisfocus=thisfocus+1;
alert(thisfocus);
if(thisfocus>totElements-1) thisfocus = totElements-1;
setFocus(thisfocus);
setChecked(thisfocus);
}
function setFocus(elementinst){
document.itemform.elements[elementinst].focus();
}
function setChecked(elementinst){
document.itemform.elements[elementinst].checked=true;
}
</script>
-
-
Never mind. I found the error myself. Problem is I had not put cancelbuble and returnvalue false to the keys.
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks