General discussion

Locked

VBScript dynamic Select Case

By LadySkyDiver ·
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

<input type=checkbox name=fieldname value=<%=rs2(fieldname)%> onclick="verify 'trim(rs2(fieldname))', <%=x%>">

rs2.movenext
LOOP

later in the page:

<input type=hidden name=str value=<%=str%>>
<input type=hidden name=stra value=<%=stra%>>

end of page:

<SCRIPT LANGUAGE=VBScript>
Sub verify(this, scase)
rsp = CStr(this)
selcase = CInt(scase)

If rsp = "ALL" then
execute (document.formname.str.value)
Else
execute (document.formname.stra.value)
End If

End Sub
</SCRIPT>

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

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

VBScript dynamic Select Case

by SteveD In reply to VBScript dynamic Select C ...

How about something like this for your Verify routine?

<SCRIPT LANGUAGE=VBScript>
Sub verify(this, scase)
rsp = CStr(this)
selcase = CInt(scase)
script = "SELECT CASE selcase " & vbCrLf
If rsp = "ALL" then
script = script & document.formname.str.value & vbCrLf & "END SELECT"
execute (script)
Else
script = script & document.formname.stra.value & vbCrLf & "END SELECT"
execute (script)
End If
End Sub
</SCRIPT>

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

I hope this helps.

Steve Diamond

Collapse -

VBScript dynamic Select Case

by LadySkyDiver In reply to VBScript dynamic Select C ...

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.

Collapse -

VBScript dynamic Select Case

by amwalsh In reply to VBScript dynamic Select C ...

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
<SCRIPT language='VBScript'>
Sub SubName
<%=s%> 'above will be inserted here
End Sub
</SCRIPT>

Collapse -

VBScript dynamic Select Case

by LadySkyDiver In reply to VBScript dynamic Select C ...

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.

Collapse -

VBScript dynamic Select Case

by LadySkyDiver In reply to VBScript dynamic Select C ...

This question was closed by the author

Back to Web Development Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums