I am trying to learn the basics of HTA but I am running into a problem.
I want a HTA GUI with a text box that I can add my own VBScript to. When I press enter in the text box internet explorer opens and prompts me to open/save the HTA file.
What is causing this to happen and how can I stop it? I am using Windows 8 and have IE10.
<html>
<head>
<HTA:APPLICATION
APPLICATIONNAME="Simple HTA"
SINGLEINSTANCE = "Yes"
SYSMENU="yes">
<title>Simple HTA</title>
<style type="text/css">
body {background-color:lightsteelblue;}
p {font:bold 18px arial;}
</style>
<script language="VBScript">
sub checkEnter
With document.parentWindow.event
if .keycode = 13 then
Validate()
End if
End With
End sub
sub validate()
x=msgbox("success")
End sub
</script>
</head>
<body>
<form>
<input type="text" onkeydown=checkEnter size=60 id="request" value="" />
<input type="button" name="btnStart" value="Start" onClick="Validate()" />
</form>
</body>
</html>
This happens, because "a little IE inside HTA" submits the form when pressing ENTER on a text input. There's a couple of ways to fix this:
If you don't need the
form
, just remove it, or replace it with adiv
.Use a function as
checkEnter
and set:I don't know if this example can help you or not but give it a try :)