Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


dependent drop down list

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,166
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> dependent drop down list
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 dependent drop down list - 6/14/2001 10:36:49 AM   
  century

 

Posts: 10
Score: 0
Joined: 6/7/2001
From: USA
Status: offline
hi,

I am trying to create a dependent drop down list, that the chosen
value in
a drop down list box can be used to determine the values of the
next drop down list box.

the first drop down list has 2 options namely Multiple Choice
Question and Short Answer Question.

If one of the value is selected, the next drop down list box has
to
display options that was determined earlier in the first drop down
list.

The 2nd drop down list will display different
options where the options are files which are retrieved from my
folders.

How can this be done using VBScript? Can anyone help me with
this problem?

Your help is much appreciated. Thank you very much.
 
 
Post #: 1
 
 Re: dependent drop down list - 6/14/2001 10:40:01 AM   
  compugenie

 

Posts: 9
Score: 0
Joined: 6/9/2001
From: USA
Status: offline
You have to put the first dropdown in a form, and the second
dropdown in another form(all on the same page). Use the
'onchange' event of the first dropdown to submit this first form to
THE SAME PAGE. Like this...
<select name="MyDropdown" size="1" onchange="submit()">

The form tag for the first form should like this:
<form name="Form1" method="post" action="thispage.asp">

thispage.asp is the current page your working on.

Near the top of the page you check to see whether or not
MyDropdown has a value:

if request.form("MyDropdown")<> ""
(the dropdown is full, now you can fill the 2nd one)
else
(it is empty, so fill the first one)
end if

(in reply to century)
 
 
Post #: 2
 
 Re: dependent drop down list - 7/2/2004 11:31:00 PM   
  jww2000

 

Posts: 1
Score: 0
Joined: 7/2/2004
From: USA
Status: offline
This is horribly inefficient but it is VB script instead of all the posts I have seen that are JavaScript. If you find a way to make this better please post.
<Script Language="Vbscript">

Sub SelectValue
Select Case document.form.Text1.value
Case ""
document.form.select1.remove 7
document.form.select1.remove 6
document.form.select1.remove 5
document.form.select1.remove 4
document.form.select1.remove 3
document.form.select1.remove 2
document.form.select1.remove 1
document.form.select1.remove 0
Case "Password Reset"
document.form.select1.remove 7
document.form.select1.remove 6
document.form.select1.remove 5
document.form.select1.remove 4
document.form.select1.remove 3
document.form.select1.remove 2
document.form.select1.remove 1
document.form.select1.remove 0
Set objOpt = document.CreateElement("OPTION")
objOpt.Value = "NDDS - PCOM"
objOpt.Text = "NDDS - PCOM"
document.form.Select1.add objOpt
Set objOpt = Nothing
document.form.Select1.selectedIndex = 0
Set objOpt = document.CreateElement("OPTION")
objOpt.Value = "Windows"
objOpt.Text = "Windows"
document.form.Select1.add objOpt
Set objOpt = Nothing
document.form.Select1.selectedIndex = 0
Set objOpt = document.CreateElement("OPTION")
objOpt.Value = "AS400"
objOpt.Text = "AS400"
document.form.Select1.add objOpt
Set objOpt = Nothing
document.form.Select1.selectedIndex = 0
Case "Hardware"
document.form.select1.remove 7
document.form.select1.remove 6
document.form.select1.remove 5
document.form.select1.remove 4
document.form.select1.remove 3
document.form.select1.remove 2
document.form.select1.remove 1
document.form.select1.remove 0
Set objOpt = document.CreateElement("OPTION")
objOpt.Value = "Printer"
objOpt.Text = "Printer"
document.form.Select1.add objOpt
Set objOpt = Nothing
document.form.Select1.selectedIndex = 0
Set objOpt = document.CreateElement("OPTION")
objOpt.Value = "Monitor"
objOpt.Text = "Monitor"
document.form.Select1.add objOpt
Set objOpt = Nothing
document.form.Select1.selectedIndex = 0
Case "Software"
document.form.select1.remove 7
document.form.select1.remove 6
document.form.select1.remove 5
document.form.select1.remove 4
document.form.select1.remove 3
document.form.select1.remove 2
document.form.select1.remove 1
document.form.select1.remove 0
Set objOpt = document.CreateElement("OPTION")
objOpt.Value = "MS Office"
objOpt.Text = "MS Office"
document.form.Select1.add objOpt
Set objOpt = Nothing
document.form.Select1.selectedIndex = 0
Set objOpt = document.CreateElement("OPTION")
objOpt.Value = "Outlook"
objOpt.Text = "Outlook"
document.form.Select1.add objOpt
Set objOpt = Nothing
document.form.Select1.selectedIndex = 0

End Select

End Sub
</script>
<form name="form">
<Select name="Text1" value="" size=1 onClick="SelectValue">
<option>Choose</option>
<option Value ="Password Reset">Password Reset</option>
<option Value ="Hardware">Hardware</option>
<option Value ="Software">Software</option>
</select>

<Select name="Select1" value="" size=1>
<option Value>Choose</option>
</select>
</form>

(in reply to century)
 
 
Post #: 3
 
 Re: dependent drop down list - 7/6/2004 1:14:16 AM   
  frank_41

 

Posts: 4
Score: 0
Joined: 7/1/2004
From: Germany
Status: offline
Here is another example. It creates an html file with a
listbox for a given number of entries and opens IE and reacts
on the buttonsclick :

<snippet>
:
myhtmlFile = createHtmlPage(arrEmails,numberOfMailEntries)
checkForError "Error creating Htm Page" ,ExitWithError

Dim myButtons,IEclosed

Set oIE = WScript.CreateObject("InternetExplorer.Application","IEApp_")
oIE.left=50 ' window position
oIE.top = 120 ' and other properties
oIE.height = 260 + 26*i
oIE.width = 500
oIE.menubar = 0 ' no menu
oIE.toolbar = 0
oIE.statusbar = 0
' commented out, because it causes a corrupted window
oIE.resizable = 0 ' disable resizing
oIE.navigate myhtmlFile ' Form
With oIE
winWidth=.document.ParentWindow.screen.width
winHeight=.document.ParentWindow.screen.height
End With
oIE.left=(winWidth- oIE.Width)/2 ' window position
oIE.top =(winHeight - oIE.height)/2 ' and other properties

' Important: wait till MSIE is ready
Do While (oIE.Busy)
WScript.Sleep(20)
Loop
oIE.document.all.OkButton.OnClick=GetRef("DialogOK")
oIE.document.all.SelAllButton.OnClick=GetRef("DialogSelAll")
oIE.document.all.NoneButton.OnClick=GetRef("DialogNone")

oIE.visible = TRUE ' keep visible
IEclosed = FALSE
myButtons = 0
Do While ( Not IEclosed ) ' Wait till OK button is clicked
If oIE <> "" then
If myButtons > 0 Then
Exit do
End If
End if
WScript.Sleep(20)
Loop
k=0
ReDim Preserve selectedEmails(k+1)
If Not IEclosed then
Set myForm = oIE.document.Forms("EmailForm")
For j=0 To (i-1)
If myButtons = 3 Then
myForm.fRemark.options(j).selected = FALSE
ElseIf myButtons = 2 Then
myForm.fRemark.options(j).selected = TRUE
End if
isSelected = myForm.fRemark.options(j).selected
If isSelected Then
selectedEmails(k) = myForm.fRemark.options(j).text
k=k+1
ReDim Preserve selectedEmails(k)
End if
next
End if
DeleteTempFile myhtmlFile
' For i=0 To k-1
' SendNotesMail mailSubject,"",selectedEmails(i),mailText,FALSE
' Next
For i=0 To k-1
If i=0 then
MailList = selectedEmails(i)
Else
MailList = MailList&","&selectedEmails(i)
End if
Next
' MailList = """" & MailList & """"
If Len(MailList) > 0 then
SendNotesMail mailSubject,"",MailList,mailText,FALSE
End If

If IEclosed = FALSE And myButtons > 0 then
oIE.Quit()
End if

Set oIE = Nothing
WScript.Quit(0)
' End of Script

' Begin of Support functions

Sub IEApp_onQuit()
IEclosed = TRUE
' WScript.Quit(1)
End Sub

Sub DialogOK
myButtons = 1
End Sub

Sub DialogSelAll
myButtons = 2
End Sub

Sub DialogNone
myButtons = 3
End Sub

Sub checkForError(sErrText,Flag)

Dim ErrStr

If Err.Number > 0 Then
ErrStr = "Error : 0x" & Hex(Err.Number) & vbCrLf
ErrStr = ErrStr & Err.Description & vbCrLf
WScript.Echo "An Error occured in " & WScript.Name & vbCrLf _
& sErrText & vbCrLf & ErrStrmailText
If Flag = ExitWithError Then
WScript.Quit(1)
Else
WScript.Quit(0)
End If
End If

End Sub


Sub ErrorExit(errTxt,errNumber)
WScript.Echo errTxt
WScript.Quit(errNumber)
End Sub

Function createHtmlPage(emailList,number)

Dim filesys,htmFile,filename
Dim path,i
path = WScript.ScriptFullName
path = Left(path, InstrRev(path, "\"))


filename = CreateTempFile("htm")
Set filesys = CreateObject("Scripting.FileSystemObject")
checkForError "Couldn't access FileSystemObject",ExitWithError
Set htmFile = filesys.CreateTextFile(filename,TRUE)
checkForError "Can't open file " & filename,ExitWithError


htmFile.Writeline("<html>")
checkForError "Can't write to file " & filename,ExitWithError
htmFile.Writeline(" ")
htmFile.Writeline("<head>")
htmFile.Writeline("<meta http-equiv=""Content-Type""")
htmFile.Writeline("content=""text/html; charset=iso-8859-1"">")
htmFile.Writeline("<title>Harvest Email Notification</title>")
htmFile.Writeline("</head>")
htmFile.Writeline(" ")
htmFile.Writeline("<body bgcolor=""#C0C0C0"">")
htmFile.Writeline("<script language=""VBScript""> ")
htmFile.Writeline("<!--")
htmFile.Writeline("Sub window_onload()")
htmFile.Writeline("' Here we may initialize the form")
htmFile.Writeline(" Set TheForm = Document.EmailForm")
htmFile.Writeline("End Sub")
htmFile.Writeline(" ")
htmFile.Writeline("'-->")
htmFile.Writeline("</script>")
htmFile.Writeline(" ")
htmFile.Writeline("<h3><FONT FACE=""Arial"">Email Notification</h3>")
htmFile.Writeline("<h4>Please select one or more email recipients you want<br>")
htmFile.Writeline("to inform from this action and click OK <br>")
htmFile.Writeline("or one of the Buttons ""Select All"" or ""None""</h4>")
htmFile.Writeline(" ")
htmFile.Writeline("<hr>")
htmFile.Writeline(" ")
htmFile.Writeline("   <input type=""button"" ID=""SelAllButton"" name=""SelAllButton"" value=""Select All"">")
htmFile.Writeline("   <input type=""button"" ID=""NoneButton"" name=""NoneButton"" value=""None""><br>")
htmFile.Writeline("<form name=""EmailForm"">")
htmFile.Writeline(" Email Recipients:<br> <SELECT size=""" & (number+1) & """ name=""fRemark"" multiple>")
htmFile.Writeline(" <Option selected value = ""Email0"">" & emailList(0)& "</Option>")
For i=1 To number
htmFile.Writeline(" <Option value = ""Email"&i&""">"& emailList(i)& "</Option>")
next
htmFile.Writeline(" </SELECT></p>")
htmFile.Writeline("     <input type=""button"" ID=""OkButton"" name=""OkButton"" value=""OK""><br>")
htmFile.Writeline("</FONT></form>")
htmFile.Writeline("</body>")
htmFile.Writeline("</html>")

checkForError "Error writing into filename " & filename ,ExitWithError
htmFile.Close

createHtmlPage = filename
End Function
:
<End snippet>

(in reply to century)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> dependent drop down list Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts