Rahul Tripathi
Rahul Tripathi

Reputation: 172578

To call a VBScript function on click of Enter key?

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.

Upvotes: 1

Views: 6369

Answers (1)

AutomatedChaos
AutomatedChaos

Reputation: 7490

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!"

Upvotes: 1

Related Questions