To call a VBScript function on click of Enter key?

两盒软妹~` 提交于 2019-12-24 10:28:38

问题


I have created a VBScript function OnRefreshList() which is called on the click of a button "Refresh List".

Sub OnRefreshList ()

Initdatatable(false)

if ReadFilters() = false then
    msgbox "It is not possible to refresh the whole orders list. Please enter more filters"
    exit sub
end if

End Sub

The "Refresh List" button is defined as

 <td class="button cmd" valign="center" nowrap id="cmdRefresh" onclick="OnRefreshList()" title="Refresh the order list">Refresh List</td>

This function is working fine when I am clicking on the button.

Now I want to call this function when I press the Enter key from the key board.

For this I tried to change the following piece of code but it didnt worked for me.

<td class="button cmd" valign="center" nowrap id="cmdRefresh" onKeydown="vbscript: if (event.keyCode==13) then OnRefreshList()" onclick="OnRefreshList()" title="Refresh the order list">Refresh List</td>

Please help me if anyone has an answer to it.


回答1:


Your onKeydown event does not have a correct VBScript statement in it. It should be:

onKeydown="vbscript: if event.keyCode=13 then OnRefreshList()" 

Notice the single = sign and the lack of parenthesis (they are not mandatory). If you are more comfortable with javascript: You can mix VBScript and Javascript:

onKeydown="javascript: if (event.keyCode==13) OnRefreshList(); //this will work too!"


来源:https://stackoverflow.com/questions/11792428/to-call-a-vbscript-function-on-click-of-enter-key

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!