×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
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 --> HTA

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

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

(OP)
I actually figured out a VBSCript hack to implement such a check:

CODE --> HTA

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close