"Andre" <aa@no.it> wrote in message
news:eZ**************@TK2MSFTNGP12.phx.gbl...
but if i understand your code, the value from ASP is put outside the SUB.
Is it not possible to get that value within the SUB dag_onchange(), because
that value must be tested in the SUB and determines the visibility style
of another SELECT in the same page etc ...
If i get that value outside SUB dag_onchange, how can i make the other
select visible?
thanks again
[snip]
The way you have described it, "Sub dag_onchange" is client-side event
script, meaning it is executed in the browser, not the server. The server
has absolutely no knowledge of events that occur in the browser. It only
knows something is going on when the form is submitted back to the server.
The server can only leave results for the client through <%=...%> script
tags that are replaced when the server prepares the page, not after it is
received in the browser. For instance, if you have this in a client event
script block:
If dag.value = "<%=AServerSideVariable%>" then
'do something
End If
the result you'll see if you view the source in the browser would be
something like:
If dag.value = "This is what the server left." then
You can't do a direct comparison such as:
If dag.value = AServerSideVariable then
In other words, in the client script you are not comparing your variable
against a server variable, you are comparing the client variable to a
literal representing an actual *value* left by the server. From the client
perspective, it is the same as if you typed the value in yourself.
Try this sample to get an idea of what I mean (the code's formatted a bit
awkwardly, but that's to avoid line-wrap problems):
**** begin sample file "testforandre.asp" ****
<% option explicit %>
<%
dim IsPostback, strMethod, TextOptionPickVal
dim TextForOptionPick, TextForTextbox
dim MagicWord, UsedMagicWord
IsPostback = false
strMethod = ""
TextForOptionPick = ""
TextForTextbox = ""
MagicWord = "boo"
UsedMagicWord = false
with request
strMethod = lcase(.servervariables("REQUEST_METHOD"))
if strMethod = "post" then
IsPostback = true
TextOptionPickVal = .form("D1")
select case TextOptionPickVal
case ""
TextForOptionPick = "Nothing"
case "1"
TextForOptionPick = "the first item"
case "2"
TextForOptionPick = "the second item"
case "3"
TextForOptionPick = "the third item"
end select
TextForTextbox = trim(.Form("T1"))
If TextForTextbox = "" then
TextForTextbox = "<b>You didn't type anything.</b>"
Else
if instr(TextForTextbox, MagicWord) > 0 then
UsedMagicWord = true
end if
TextForTextbox = "You typed: " & _
"<font color=""red""><b>" & _
TextForTextbox & "</b></font>"
end if
end if
end with
%>
<html>
<head>
<title>Test Posting Script for Andre</title>
</head>
<body>
<form method="POST">
<p>Hello, Andre. Postback is <%=IsPostback%>.</p>
<% if IsPostBack then 'form was submitted %>
<p>You picked <%=TextForOptionPick%>
from the list (<%=TextOptionPickVal%>)</p>
<p><%=TextForTextbox%></p>
<p><% if UsedMagicWord then %>
You typed the magic word!
<% else %>
You did not type the magic word.
<% end if %></p>
<p>Is it making more sense now?</p>
<p>(use 'back' to try it again)</p>
<% else 'form wasn't submitted %>
<p>Fill out the form and click submit.</p>
<p>Pick one of these:
<select size="1" name="D1">
<option value="">(Please pick)</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">A Third Option</option>
</select></p>
<p>Type something here:
<input type="text" name="T1" size="20"></p>
<% if not UsedMagicWord then %>
(Try typing "<%=MagicWord%>" anywhere in the
textbox and see what happens.)
<% end if %>
<p>
<input type="submit" value="Submit" name="B1"></p>
<% end if %>
</form>
</body>
</html>
*** end of "testforandre.asp" ****
Run the page. In the browser, view | source both before and after you
submit it and compare it to the script code. Try it a number of times with
different inputs. You'll be able to see where the server variables were
inserted, and how the logic in the client script determined what to display
based on what you entered or whether you had submitted the form.
While I did not show you actual interaction between client event script and
the server, the principles are essentially the same: The server can work
with values you submit via form input controls, and you get back literal
values from the server that you can test in the client's script. However,
you can't directly mix the two.
I hope this clears it up a bit more.
Alan