vbscript - HTA : how to pick up value from each drop down list and search? -
i trying make hta working, add value each drop down list , search accordingly in directory can selected button. can make form of hta dont know how make search working.
also how can move directory selection button beginning of line? user can pick directory first pick want search.
<html> <head> <hta:application id="2014-03" applicationname="2014-03" version="1.1" border="thin" borderstyle="static" caption="yes" contextmenu="no" icon="c:\icon\32x32.ico" innerborder="no" maximizebutton="no" minimizebutton="no" navigatable="no" scroll="no" scrollflat="no" selection="no" showintaskbar="yes" singleinstance="yes" sysmenu="yes" windowstate="normal" > <script language="vbscript"> sub runsearch_onclick() msgbox "success!" end sub sub testsub each objoption in optionchooser.options if objoption.selected msgbox objoption.innertext end if next end sub sub testsub1 each objoption in optionchooser.options if objoption.selected msgbox objoption.innertext end if next end sub sub windowsload set objshell = createobject("shell.application") set objfolder = objshell.browseforfolder (0, "select folder enumerate :", (0)) if objfolder nothing wscript.quit else set objfolderitem = objfolder.self objpath = objfolderitem.path end if set objfso = createobject("scripting.filesystemobject") set objfolder = objfso.getfolder(objpath) each objfile in objfolder.files if objfolder.files.count > 0 window.document.title = "information " & objpath strhtml = strhtml & "<td><font color = blue>" & objfile.name & "</font></br>" dataarea.innerhtml = strhtml end if next end sub </script> </head> <body> <select id=extension size="1" name="optionchooser" onchange="testsub"> <option value="0">selet file type</option> <option value="1">.txt</option> <option value="2">.pdf</option> <option value="3">.jpg</option> <option value="4">.mp3</option> </select> <select id=year size="1" name="optionchooser" onchange="testsub1"> <option value="0">select year</option> <option value="1">2014</option> <option value="2">2013</option> <option value="3">2012</option> <option value="3">2011</option> <option value="3">2010</option> </select> <select id=month size="1" name="optionchooser" onchange="testsub2"> <option value="0">select month</option> <option value="1">01</option> <option value="2">02</option> <option value="3">03</option> <option value="1">04</option> <option value="2">05</option> <option value="3">06</option> <option value="1">07</option> <option value="2">08</option> <option value="3">09</option> <option value="1">10</option> <option value="2">11</option> <option value="3">12</option> </select> <input type = "button" value = "browse folder" name = "run_button" onclick = "windowsload"><p></td> <input type="button" value="search" name="runsearch"> </body> </html>
the final hta should this, search result need displayed below drop down list text file within scrollable window , having full path of files.
in next hta
necessary changes made display search result below drop down list scrollable text area , having full paths of files.
- on start, user prompted select initial directory (see
windowsload
call withinwindow_onload
procedure; all files displayed no search criteria selected yet. - search completed in code extension show possible how-to approach (one of few).
- used simple stylesheet.
- some variables defined script (application) global keep visibility within procedures.
- further elementary changes: see code below.
the code:
<html> <head> <hta:application id="2014-03" applicationname="2014-03" version="1.1" border="thin" borderstyle="static" caption="yes" contextmenu="no" icon="c:\icon\32x32.ico" innerborder="no" maximizebutton="no" minimizebutton="no" navigatable="no" scroll="no" scrollflat="no" selection="no" showintaskbar="yes" singleinstance="yes" sysmenu="yes" windowstate="normal" > <!-- '************************ '* stylesheet '************************ --> <style> body { background-color: buttonface; font-family: arial, helvetica, sans-serif; font-size: 8pt; margin-top: 2px; margin-left: 8px; margin-right: 3px; margin-bottom: 3px; } .button { font-family: arial, helvetica, sans-serif; font-size: 8pt; width: 40px; } textarea { background-color: yellow; font-family: arial; font-size: 8pt; margin-left: 3px; margin-right: 3px; } </style> <script language="vbscript"> '************************ '* global variables '************************ set objfso = createobject("scripting.filesystemobject") set objshell = createobject("shell.application") objpath = "" strhtml = "" chooser0 = "" chooser1 = "" chooser2 = "" '************************ '* window_onload '************************ sub window_onload self.focus() self.resizeto 800,600 dataarea.innerhtml = "<textarea cols=122 rows=25></textarea>" windowsload end sub sub runsearch_onclick() 'msgbox "success!" windowsload end sub sub testsub if optionchooser.value = "0" chooser0 = "" else each objoption in optionchooser.options if objoption.selected chooser0 = objoption.innertext exit end if next end if end sub sub testsub1 each objoption in optionchooser1.options if objoption.selected msgbox objoption.innertext end if next end sub sub testsub2 each objoption in optionchooser2.options if objoption.selected msgbox objoption.innertext end if next end sub sub whichfolder prevpath = objpath set objfolder = objshell.browseforfolder _ (0, "select folder enumerate :", (0)) if objfolder nothing msgbox "bye!" self.close() else set objfolderitem = objfolder.self objpath = objfolderitem.path end if if prevpath <> "" windowsload end sub sub windowsload if objpath = "" whichfolder end if set objfolder = objfso.getfolder(objpath) window.document.title = "information " & objpath & " " & chooser0 strhtml = "<textarea cols=122 rows=25>" showsubfolders objfolder, chooser0 dataarea.innerhtml = strhtml end sub sub showsubfolders(ffolder, strext) 'strhtml = strhtml & chr(10) & ffolder.path & chr(10) set objfolder = objfso.getfolder(ffolder.path) set colfiles = objfolder.files each objfile in colfiles if strext = "" or ucase(strext) = _ "." & ucase(objfso.getextensionname(objfile.name)) strhtml = strhtml & objfile.path & chr(10) end if next each subfolder in ffolder.subfolders showsubfolders subfolder, strext next end sub </script> </head> <body> <select id=extension size="1" name="optionchooser" onchange="testsub"> <option value="0">selet file type</option> <option value="1">.txt</option> <option value="2">.pdf</option> <option value="3">.jpg</option> <option value="4">.mp3</option> </select> <select id=year size="1" name="optionchooser1" onchange="testsub1"> <option value="0">select year</option> <option value="1">2014</option> <option value="2">2013</option> <option value="3">2012</option> <option value="3">2011</option> <option value="3">2010</option> </select> <select id=month size="1" name="optionchooser2" onchange="testsub2"> <option value="0">select month</option> <option value="1">01</option> <option value="2">02</option> <option value="3">03</option> <option value="1">04</option> <option value="2">05</option> <option value="3">06</option> <option value="1">07</option> <option value="2">08</option> <option value="3">09</option> <option value="1">10</option> <option value="2">11</option> <option value="3">12</option> </select> <input type = "button" value = "browse folder" name = "run_button" onclick = "whichfolder"><p> <input type="button" value="search" name="runsearch"><p> <div id="dataarea" name="dataarea"></div> </body> </html>