Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate that HTA text input boxes aren't blank on submission

Status
Not open for further replies.

bdwilcox

Technical User
Jul 7, 2022
6
0
1
US
I was wondering if anyone has either a VBScript or JavaScript subroutine that will work in a simple HTA to make sure neither of the two mandatory text boxes [Machine Name (CompID) & Program Name (ProgID)] are blank when the user presses the Click to Find the Program button? I would like it to pop up a warning saying blank fields aren't allowed then just go back to the HTA so they can correct and re-submit (but without displaying the scripting error pop-up I get now).

After a bunch of Googling, I've found some JavaScript validation routines but they all seem to use CSS 2 or 3 form controls that I believe HTA doesn't support (from what I understand, which definitely could be totally wrong). I apologize for my sloppy HTA but this is what I could hack together at this point. Any help would be greatly appreciated.

Code:
<!DOCTYPE html>

<html>

<head>
<title>Program Finder</title>

       <script language="VBScript">
           Option Explicit
           Dim width, height
           width  = 900 -1
           height = 500 -1
           self.ResizeTo width, height
           self.MoveTo (screen.availWidth - width)/2, (screen.availHeight - height)/2
      </script>

<HTA:APPLICATION
     APPLICATIONNAME="Product Finder"
     Caption="Yes"
     MaximizeButton="No"
     MinimizeButton="No"
     SCROLL="No"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="Normal"
     BORDER="Normal"
     Icon=C:\Windows\System32\Magnify.exe
>

</head>

<script language="VBScript">
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set Ws = CreateObject("WScript.Shell")
sub FindProg
MySoftware = ProgID.value
strComputer = CompID.value
Set objWMIService = GetObject("winmgmts:" _
  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
  ("Select * from Win32_Product where Name Like " & CommandLineLike(MySoftware))

For Each objSoftware in colSoftware
  x=MsgBox ("Caption" & vbtab & vbtab & objSoftware.Caption & vbCrLf & _
  "Description:" & vbtab & objSoftware.Description & vbCrLf & _
  "Identifying #:" & vbtab & objSoftware.IdentifyingNumber & vbCrLf & _
  "Install Date:" & vbtab & vbtab & objSoftware.InstallDate2 & vbCrLf & _
  "Install Location:" & vbtab & objSoftware.InstallLocation & vbCrLf & _
  "Install State:" & vbtab & objSoftware.InstallState & vbCrLf & _
  "Name:" & vbtab & vbtab & objSoftware.Name & vbCrLf & _
  "Package Cache:" & vbtab & objSoftware.PackageCache & vbCrLf & _
  "SKU Number:" & vbtab & objSoftware.SKUNumber & vbCrLf & _
  "Vendor:" & vbtab & vbtab & objSoftware.Vendor & vbCrLf & _
  "Version:" & vbtab & vbtab & objSoftware.Version)
Next

End Sub

Sub CloseBtn_OnClick
    Window.Close
End Sub

Function CommandLineLike(MySoftware)
    MySoftware = Replace(MySoftware, "\", "\\")
    CommandLineLike = "'%" & MySoftware & "%'"
End Function

</script>

<body>
<font face=Verdana>
<text>Find out if a program is installed on a remote computer</text> <br> <br>
<text>Machine Name or IP Address:</text>
<input type="text" name="CompID" size="30"> <br> <br>
<text>Partial Name of a Program:&nbsp;&nbsp;&nbsp<text>
<input type="text" name="ProgID" size="30"> <br> <br>
<text>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp</text>
<button onclick="FindProg">Click to Find the Program</button>
<Input Type = "Button" Name = "CloseBtn" VALUE = "Close Window">
</body>
 
I actually figured out a VBSCript hack to implement such a check:

Code:
<!DOCTYPE html>

<html>

<head>
<title>Program Finder v.1a</title>

       <script language="VBScript">
           Option Explicit
           Dim width, height
           width  = 900 -1
           height = 500 -1
           self.ResizeTo width, height
           self.MoveTo (screen.availWidth - width)/2, (screen.availHeight - height)/2
      </script>

<HTA:APPLICATION
     APPLICATIONNAME="Program Finder"
     Caption="Yes"
     MaximizeButton="No"
     MinimizeButton="No"
     SCROLL="No"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="Normal"
     BORDER="Normal"
     Icon=C:\Windows\System32\Magnify.exe
>

</head>

<script language="VBScript">
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set Ws = CreateObject("WScript.Shell")
sub FindProg
MySoftware = ProgID.value
strComputer = CompID.value
Set objWMIService = GetObject("winmgmts:" _
  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
  ("Select * from Win32_Product where Name Like " & CommandLineLike(MySoftware))

For Each objSoftware in colSoftware
  x=MsgBox ("Caption" & vbtab & vbtab & objSoftware.Caption & vbCrLf & _
  "Description:" & vbtab & objSoftware.Description & vbCrLf & _
  "Identifying #:" & vbtab & objSoftware.IdentifyingNumber & vbCrLf & _
  "Install Date:" & vbtab & vbtab & objSoftware.InstallDate2 & vbCrLf & _
  "Install Location:" & vbtab & objSoftware.InstallLocation & vbCrLf & _
  "Install State:" & vbtab & objSoftware.InstallState & vbCrLf & _
  "Name:" & vbtab & vbtab & objSoftware.Name & vbCrLf & _
  "Package Cache:" & vbtab & objSoftware.PackageCache & vbCrLf & _
  "SKU Number:" & vbtab & objSoftware.SKUNumber & vbCrLf & _
  "Vendor:" & vbtab & vbtab & objSoftware.Vendor & vbCrLf & _
  "Version:" & vbtab & vbtab & objSoftware.Version)
Next

End Sub

Sub CloseBtn_OnClick
    Window.Close
End Sub

Function CommandLineLike(MySoftware)
    MySoftware = Replace(MySoftware, "\", "\\")
    CommandLineLike = "'%" & MySoftware & "%'"
End Function

Sub CheckforBlanks
if CompID.value = "" then
CompIDValue = 0
Else
CompIDValue = 1
end if
if ProgID.value = "" then
ProgIDValue = 0
Else
ProgIDValue = 1
end if
CombinedValue = CompIDValue + ProgIDValue
if CombinedValue < 2 then
ErrorPopup=MsgBox ("Fields can't be blank!  Please press the OK button, fill out both fields then try again.",vbExclamation,"Blank Fields Found!")
Else
FindProg
end if
End Sub

</script>

<body>
<font face=Verdana>
<text>Find out if a program is installed on a remote computer</text> <br> <br>
<text>Machine Name or IP Address:</text>
<input type="text" name="CompID" size="30"> <br> <br>
<text>Partial Name of a Program:&nbsp;&nbsp;&nbsp<text>
<input type="text" name="ProgID" size="30"> <br> <br>
<text>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp</text>
<button onclick="CheckforBlanks">Click to Find the Program</button>
<Input Type = "Button" Name = "CloseBtn" VALUE = "Close Window">
</body>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top