Discussion Locked

VBScript dynamic Select Case

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have a hidden field with a select case built into it. I need to run the select case from an onclick event in VBScript. Here's an example:

DO UNTIL rs2.eof
If rs2(fieldname) = "ALL" then
str = str & "CASE " & x & vbCrLF & "document.formname.fieldname" & x & "." & y & ".1.checked = false" & vbCrLf
Else
stra = stra & "CASE " & x & vbCrLf & "document.formname.fieldname" & x & "." & y & ".1.checked = false" & vbCrLf
End If

onclick="verify 'trim(rs2(fieldname))', <%=x%>">

rs2.movenext
LOOP

later in the page:

>
>

end of page:

However, I need it to run only the appropriate select case items. The textbox str would have something like:

CASE 0
document.formname.fieldname0.1.1.checked = false
CASE 0
document.formname.fieldname0.2.1.checked = false
CASE 1
document.formname.fieldname1.1.1.checked = false
CASE 1
document.formname.fieldname1.1.1.checked = false
...etc.

How would I get the VBScript sub to execute only those items in Case 0? or Case 1? etc???

Your help is GREATLY appreciated. Thank you!

Regards,
Cora

5 replies

by steved

How about something like this for your Verify routine?

I haven't tried it, but it seems to me no other changes should be necessary.

I hope this helps.

Steve Diamond

by ladyskydiver

Thank you! This helped get me headed in the right direction. I took a little of your answer and a little of another answer, combined the 2 and it worked.

by amwalsh

It looks like you are just trying to dynamically create a select case clause that will be executed on the client side. Don't put this in the hidden field. Use View Source in your browser to see the code that is created.

'Server side code
s ="Select Case Expression " & Chr(13)
While rs.EOF
s = s & " Case x" & Chr(13)
s = s & " whateverYouNeedToDo"
rs.MoveNext
Wend
s = s & "End Select" & Chr(13)

'Client Side Code

by ladyskydiver

Thank you! This helped get me headed in the right direction. I took a little of your answer and a little of another answer, combined the 2 and it worked.

This discussion is closed to new replies.