![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Unable to retrieve value from drop down list (values read from textfile) Hi I have a txt file containing client names. What I am trying to do is create a HTA with a drop down box with the list of client names. WHen I select a client name and click next I will do something with that information. To start with I thought I'd get a message box telling me what client I had selected. The drop down box is populated correctly, but when I select a client and click next, the message box is blank. clientList.txt contains (sample data) steven andrews bob wilson amanda peterson What I am using is as follows: <html> <SCRIPT Language="VBScript"> sub LoadDropdown Set oShell = CreateObject( "WScript.Shell" ) TempDirectory=oShell.ExpandEnvironmentStrings("%temp%") Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(TempDirectory&"\clientList.txt", 1) strClientData=objFile.ReadAll objFile.Close arrClientData = Split(strClientData,vbNewLine) For Each strClientData in arrClientData Set objOption = Document.createElement("OPTION") objOption.Text = strClientData DropDown1.Add(objOption) Next end Sub sub NextSelected() Msgbox "This: "&dropdown1.value end Sub </SCRIPT> <select size="1" name="DropDown1"> </select> <input id=onebutton class="button" type="button" value="Next" name="one_button" onClick="NextSelected"><p> <input id=twobutton class="button" type="button" value="Populate" name="two_button" onClick="LoadDropDown"<p> </body> </html> |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Unable to retrieve value from drop down list (values read fromtext file) Bah Another 10 minutes searching provided this: <html> <SCRIPT Language="VBScript"> sub LoadDropdown Set oShell = CreateObject( "WScript.Shell" ) TempDirectory=oShell.ExpandEnvironmentStrings("%temp%") Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(TempDirectory&"\clientList.txt", 1) Do Until objFile.AtEndOfStream strLine = objFile.ReadLine Set objOption = Document.createElement("OPTION") objOption.Text = strLine objOption.Value = strLine DropDown1.Add(objOption) Loop objFile.Close End Sub sub NextSelected() Msgbox "This: "&dropdown1.value end Sub </SCRIPT> <select size="1" name="DropDown1"> </select> <input id=onebutton class="button" type="button" value="Next" name="one_button" onClick="NextSelected"><p> <input id=twobutton class="button" type="button" value="Populate" name="two_button" onClick="LoadDropDown"<p> </body> </html> Essentially a change to the way the file is read and the drop down box is created. This works fine. Steve Steven Andrews wrote: Quote: > Hi > > I have a txt file containing client names. What I am trying to do is > create a HTA with a drop down box with the list of client names. WHen I > select a client name and click next I will do something with that > information. To start with I thought I'd get a message box telling me > what client I had selected. The drop down box is populated correctly, > but when I select a client and click next, the message box is blank. > > clientList.txt contains (sample data) > > steven andrews > bob wilson > amanda peterson > > > What I am using is as follows: > > > <html> > <SCRIPT Language="VBScript"> > > sub LoadDropdown > > Set oShell = CreateObject( "WScript.Shell" ) > TempDirectory=oShell.ExpandEnvironmentStrings("%temp%") > > Set objFSO = CreateObject("Scripting.FileSystemObject") > Set objFile = objFSO.OpenTextFile(TempDirectory&"\clientList.txt", 1) > strClientData=objFile.ReadAll > objFile.Close > > arrClientData = Split(strClientData,vbNewLine) > For Each strClientData in arrClientData > Set objOption = Document.createElement("OPTION") > objOption.Text = strClientData > DropDown1.Add(objOption) > Next > end Sub > > > sub NextSelected() > Msgbox "This: "&dropdown1.value > end Sub > > > </SCRIPT> > > > <select size="1" name="DropDown1"> > > </select> > > <input id=onebutton class="button" type="button" value="Next" > name="one_button" onClick="NextSelected"><p> > <input id=twobutton class="button" type="button" value="Populate" > name="two_button" onClick="LoadDropDown"<p> > </body> > </html> |
My System Specs![]() |
| | #3 (permalink) |
| | RE: Unable to retrieve value from drop down list (values read from tex If you care.... You don't HAVE to give a VALUE to each <OPTION> if you don't want to. Instead, you could code: sub NextSelected() Msgbox "This: " & dropdown1.options(dropdown1.selectedIndex).text end Sub |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Unable to retrieve value from drop down list (values read fromtex Old Pedant wrote: Quote: > If you care.... > > You don't HAVE to give a VALUE to each <OPTION> if you don't want to. > > Instead, you could code: > > sub NextSelected() > Msgbox "This: " & dropdown1.options(dropdown1.selectedIndex).text > end Sub > > That actually makes more sense and I think easier to read code... Thanks |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| How do i retrieve only the values from array ? | PowerShell | |||
| Read-Host values into an Array | PowerShell | |||
| Read values returned from a powershell command in VB.Net | PowerShell | |||
| How to read Vista registry values containing @DllFilename.dll? | Vista General | |||