質問

I have an HTA application which has an image. When clicked on this image calls a sub. When an 'Enter' Key is hit another sub is called.

The problem here is when an Enter key is hit both the subs are called.

See the code below for example ...

<head>

<HTA:APPLICATION>



</head>


<script language="VBScript">

Sub EnterKey

    If window.event.Keycode = 13 then
        MsgBox "Enter was pressed"
    End If

    If window.event.Keycode = 27 then
        MsgBox "Escape was pressed"
    End If

End Sub

Sub DeleteThis
    MsgBox "Image was clicked"
End Sub

</script>

<body onkeypress="EnterKey">

<input type="image" height="27" width="27" onclick="DeleteThis" src="Search.png" alt="Database Search">

</body>

When 'Enter' key is hit both "Image was clicked" & "Enter was pressed" gets displayed. I do not want the "Image was clicked" message to be displayed when 'Enter' is clicked.

Any Suggestions ?

役に立ちましたか?

解決 2

Ok i figured this out, i have changed the below code for the image link

<input type="image" height="27" width="27" onclick="DeleteThis" src="Search.png" alt="Database Search">

to

<img src="search.png" alt="Database Search" width="27" height="27" onclick="DeleteThis">

Apparently it depends on the tag one uses ...

他のヒント

You could either remove onclick="DeleteThis" to prevent that function from being called at all.

Or you have to implement a condition into the function DeleteThis, to prevent the output if the key pressed was the enter key.

Sub DeleteThis
    If window.event.Keycode != 13 then
        MsgBox "Image was clicked"
    End If
End Sub
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top