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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

updating dynamic select menu in hta without submitting form 4

Status
Not open for further replies.

edushkushot

Programmer
Jan 11, 2004
15
US
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 :)
 
Maybe some ideas here: thread329-43991

Hope This Help
PH.
 
It depends on where the new information is coming from - I have used an xml file to store the data and then dynamically generate the select menu by reloading and re querying the xml file, perhaps this could be a solution, however it would only work on xml compliant browsers.

Just an Idea
 
I use <DIV> tags to do this. I have a webpage for people to configure what printer to use for another app.. they pick the print server from a dropdown then it dynamically updates the second dropdown for printer. Here's an example.

<script language=vbscript>
Function updatedrop()
if data.server.value = &quot;1&quot; then
prt.innerHTML=&quot;Server 1 Printer: <select name=printer><option>printer1</option><option>printer2</option></select>&quot;
else
prt.innerHTML=&quot;Server 2 Printer: <select name=printer><option>printer3</option><option>printer4</option></select>&quot;
end if
end function
</script>
<html>
<body onload=vbscript:updatedrop()>
<form name=data>
<select onchange=vbscript:updatedrop() name=server><option value='1'>print-server-1</option>
<option value='2'>print-server-2</option></select><BR>
<div id=prt></div>

Hope that helps!
 
I like the prospect of the div id, except the select dropdown's options are dynamic and are filled in with a loop. But the DIV.innerHTML would just overwrite itself with the most recent option.

Any ideas to get around that and still use a loop within a div.

G :)
 
sure just use dom to create the dropdown

clear dropdown

Code:
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(&quot;option&quot;);
objOption.text = myOption[i]
objOption.value = myValue[i]
if(document.all && !window.opera)
  {objSelect.add(objOption);}
 else
  {objSelect.add(objOption, null);};
}}

hope this helps

Simon
 
Ok, guys. Here is the finished HTA APP code. Thanks everyone for your help and comments. I gave everyone props.

I admit the functions in here could be written even better, but this is the prototype, and it works. Program gets data from a database, populates the first select dropdown with Facility Names and when the user selects a Facility the Inspection Dates dropdown is cleared and updated with only the correct inspection dates for that facility. The code is below, if anyone wants to use it or make it better. Again, Thanks.


Code:
<HTML>
<HEAD>
   <TITLE>Facility Inspection Report System</TITLE>

   <HTA:APPLICATION
   ID = &quot;FIR&quot;
   APPLICATIONNAME = &quot;FIR&quot;
   BORDER = &quot;thick&quot;
   CAPTION = &quot;yes&quot;
   SHOWINTASKBAR = &quot;yes&quot;
   SINGLEINSTANCE = &quot;yes&quot;
   SYSMENU = &quot;yes&quot;
   WINDOWSTATE = &quot;normal&quot;
   SCROLL = &quot;yes&quot;
   SCROLLFLAT = &quot;no&quot;
   VERSION = &quot;1.01b&quot;
   INNERBORDER = &quot;yes&quot;
   SELECTION = &quot;yes&quot;
   MAXIMIZEBUTTON = &quot;yes&quot;
   MINIMIZEBUTTON = &quot;yes&quot;
   NAVIGABLE = &quot;yes&quot;
   CONTEXTMENU = &quot;yes&quot;
   BORDERSTYLE = &quot;normal&quot;
   >
<script language=&quot;javascript&quot;>
<!--
self.resizeTo(690, 400);

//-->
</script>
<script language=&quot;vbscript&quot;>

'Start of FIR Report Generation Tool
'Create a command object to execute Advancded SQL Statements
Set objCmd = CreateObject(&quot;ADODB.Command&quot;)
Set objCmd2 = CreateObject(&quot;ADODB.Command&quot;)

'Initialize Connection String to connect to an MS Access Database
sConnect = &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Facilities Management.mdb;Persist Security Info=False&quot;
objCmd.ActiveConnection = sConnect	'Connect to database
objCmd2.ActiveConnection = sConnect	'Connect to database

objCmd.CommandText = &quot;SELECT DISTINCT [Facilities].Facility FROM [Facilities] WHERE [Facilities].Facility = [Facilities].[Facility]&quot;

'Create the actual recordset to be used in this script and retrieve or display information from database
Set objRS 	= CreateObject(&quot;ADODB.Recordset&quot;)
Set objRS 	= objCmd.Execute






function createSelect1()

	while not objRS.EOF
		Set objOption = document.createElement(&quot;option&quot;)
		objOption.Text  = objRS(&quot;Facility&quot;)
		objOption.Value = objRS(&quot;Facility&quot;)
		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 = &quot;SELECT DISTINCT [Facility Inspections].Facility, [Facility Inspections].[Inspection Date] FROM [Facility Inspections] WHERE [Facility Inspections].Facility = '&quot; & fname1 & &quot;'&quot;
		
		Set objRS2 	= CreateObject(&quot;ADODB.Recordset&quot;)
		Set objRS2 	= objCmd2.Execute


	while not objRS2.EOF
		Set objOption2 = document.createElement(&quot;option&quot;)
		objOption2.Text  = objRS2(&quot;Inspection Date&quot;)
		objOption2.Value = objRS2(&quot;Inspection Date&quot;)
		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(&quot;WScript.Shell&quot;)
	Set shellExec = objShell.Exec(&quot;%comspec% /c cscript.exe  firgenerator.vbs &quot; & chr(34) & fname & chr(34) & &quot; &quot; & fdate) 
	
	eoutput = shellExec.StdErr.ReadAll


		document.write &quot;<table width=640 border=0 cellpadding=0>&quot;
		document.write &quot;<tr>&quot;
		document.write &quot;<td><img src=halogo.jpg  border=0 ></img>&quot;
		document.write &quot;</td>&quot;
		document.write &quot;<td width=50> </td>&quot;

			if eoutput = &quot;&quot; then
				document.write &quot;<td width=350><font size=3pt face=Arial><b>The report was generated successfully.  To create another report, click the link below.</b></font>&quot;
			else
				if InStr(eoutput, &quot;Either BOF or EOF is True&quot;) <> 0 then
					document.write &quot;<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>&quot; & &quot;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>&quot;
				end if	
			end if

		document.write &quot;</br></br>&quot;
		document.write &quot;<a href=fir.hta>Back</a>&quot;
		document.write &quot;</tr>&quot;
		document.write &quot;</table>&quot;

	Set objShell = Nothing
end function					

</SCRIPT>
</HEAD>
<body>
<table width=&quot;640&quot; border=&quot;0&quot; cellpadding=&quot;0&quot;>
<tr>
<td><img src=&quot;halogo.jpg&quot;  border=&quot;0&quot; alt=&quot;Heartland Alliance for Human Needs & Human Rights&quot;>
</td>
<td width=&quot;50&quot;> </td>
<td width=&quot;350&quot;><font size=&quot;3pt&quot; face=&quot;Arial&quot;><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=&quot;firs&quot; method=&quot;post&quot; action=&quot;fir.hta&quot;>
					
					<select name=facilities id=facilities onChange=&quot;createSelect2()&quot;>
					<option value=&quot;---Select A Facility---&quot;>---Select A Facility---</option>
					<SCRIPT Language=&quot;VBScript&quot;>
						createSelect1()
					</SCRIPT> 
					</select>
					</br>
					</br>
					<select name=inspectiondate id=inspectiondate onChange=&quot;createReport()&quot;>
					<option value=&quot;---Select An Inspection Date---&quot;>---Select An Inspection Date---</option>
					
					</select>					
				</form>
</td>
</tr>
</table>



</body>
</HTML>




G :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top