edushkushot
Programmer
Does anyone have any ideas on how to dynamically update a select dropdown menu in an HTA application based on a user's choice from another select dropdown without submitting the form?
G
G
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
function clearSelect(i,x){
var objSelect=document.forms(i).elements[x];
while(objSelect.options.length > 1){objSelect.remove(1);}
return objSelect;
}
function createSelect(){
var objSelect = clearSelect(myFormNumber/name,selectName)
// run loop to create options
// myOption and myValue are 2 array that store option info
// you could just as easily use multi-dimensional arrays
// to store multiple option lists
for(var i=0;i<myOption.length;i++){
objOption = document.createElement("option");
objOption.text = myOption[i]
objOption.value = myValue[i]
if(document.all && !window.opera)
{objSelect.add(objOption);}
else
{objSelect.add(objOption, null);};
}}
<HTML>
<HEAD>
<TITLE>Facility Inspection Report System</TITLE>
<HTA:APPLICATION
ID = "FIR"
APPLICATIONNAME = "FIR"
BORDER = "thick"
CAPTION = "yes"
SHOWINTASKBAR = "yes"
SINGLEINSTANCE = "yes"
SYSMENU = "yes"
WINDOWSTATE = "normal"
SCROLL = "yes"
SCROLLFLAT = "no"
VERSION = "1.01b"
INNERBORDER = "yes"
SELECTION = "yes"
MAXIMIZEBUTTON = "yes"
MINIMIZEBUTTON = "yes"
NAVIGABLE = "yes"
CONTEXTMENU = "yes"
BORDERSTYLE = "normal"
>
<script language="javascript">
<!--
self.resizeTo(690, 400);
//-->
</script>
<script language="vbscript">
'Start of FIR Report Generation Tool
'Create a command object to execute Advancded SQL Statements
Set objCmd = CreateObject("ADODB.Command")
Set objCmd2 = CreateObject("ADODB.Command")
'Initialize Connection String to connect to an MS Access Database
sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Facilities Management.mdb;Persist Security Info=False"
objCmd.ActiveConnection = sConnect 'Connect to database
objCmd2.ActiveConnection = sConnect 'Connect to database
objCmd.CommandText = "SELECT DISTINCT [Facilities].Facility FROM [Facilities] WHERE [Facilities].Facility = [Facilities].[Facility]"
'Create the actual recordset to be used in this script and retrieve or display information from database
Set objRS = CreateObject("ADODB.Recordset")
Set objRS = objCmd.Execute
function createSelect1()
while not objRS.EOF
Set objOption = document.createElement("option")
objOption.Text = objRS("Facility")
objOption.Value = objRS("Facility")
document.firs.facilities.Add objOption
objRS.MoveNext
wend
end function
function clearSelect2()
while document.firs.inspectiondate.options.length > 1
document.firs.inspectiondate.remove(1)
wend
end function
function createSelect2()
clearSelect2()
fname1 = firs.facilities.options.Value
objCmd2.CommandText = "SELECT DISTINCT [Facility Inspections].Facility, [Facility Inspections].[Inspection Date] FROM [Facility Inspections] WHERE [Facility Inspections].Facility = '" & fname1 & "'"
Set objRS2 = CreateObject("ADODB.Recordset")
Set objRS2 = objCmd2.Execute
while not objRS2.EOF
Set objOption2 = document.createElement("option")
objOption2.Text = objRS2("Inspection Date")
objOption2.Value = objRS2("Inspection Date")
document.firs.inspectiondate.Add objOption2
objRS2.MoveNext
wend
end function
function createReport()
fname = firs.facilities.options.Value
fdate = firs.inspectiondate.options.Value
Set objShell = CreateObject("WScript.Shell")
Set shellExec = objShell.Exec("%comspec% /c cscript.exe firgenerator.vbs " & chr(34) & fname & chr(34) & " " & fdate)
eoutput = shellExec.StdErr.ReadAll
document.write "<table width=640 border=0 cellpadding=0>"
document.write "<tr>"
document.write "<td><img src=halogo.jpg border=0 ></img>"
document.write "</td>"
document.write "<td width=50> </td>"
if eoutput = "" then
document.write "<td width=350><font size=3pt face=Arial><b>The report was generated successfully. To create another report, click the link below.</b></font>"
else
if InStr(eoutput, "Either BOF or EOF is True") <> 0 then
document.write "<td width=350><font face=Arial color=red><h4>ERROR CODE: 001</h4></font><font size=2pt face=Arial color=red><b>The report could not be created due to the following error. . .</br></br>" & "The selected Facility and Inspection Date do not match any records. Please check the Facility Name and Inspection Date. To try again, click the link below to start over.</b></font>"
end if
end if
document.write "</br></br>"
document.write "<a href=fir.hta>Back</a>"
document.write "</tr>"
document.write "</table>"
Set objShell = Nothing
end function
</SCRIPT>
</HEAD>
<body>
<table width="640" border="0" cellpadding="0">
<tr>
<td><img src="halogo.jpg" border="0" alt="Heartland Alliance for Human Needs & Human Rights">
</td>
<td width="50"> </td>
<td width="350"><font size="3pt" face="Arial"><b>W</b>elcome to the Facility Inspections Report Generator.
To generate a report, select a facility from the dropdown
menu below. </font>
</br>
</br>
<form name="firs" method="post" action="fir.hta">
<select name=facilities id=facilities onChange="createSelect2()">
<option value="---Select A Facility---">---Select A Facility---</option>
<SCRIPT Language="VBScript">
createSelect1()
</SCRIPT>
</select>
</br>
</br>
<select name=inspectiondate id=inspectiondate onChange="createReport()">
<option value="---Select An Inspection Date---">---Select An Inspection Date---</option>
</select>
</form>
</td>
</tr>
</table>
</body>
</HTML>