Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto handler. Please help

Status
Not open for further replies.

JohnPham

Programmer
Jul 9, 2001
34
US
Hi,
Any One has any idea on this, please help:
<%
'on this server side I request some string value:
var1= request.querystring(&quot;id&quot;)

%>
<html>
<head>
<Script language=&quot;VbScript&quot;>
What should I use event handler for this client side in order to have the HTML option select auto load up. For example when var1=&quot;admin&quot; then the Admin option below auto select.

</Script>
</head>

<body>

<SELECT id=selectUsr name=selectUsr width=&quot;100%&quot; style=&quot;WIDTH: 199px&quot; >
<OPTION value=&quot;0&quot; > Select User Role</OPTION>
<OPTION value=&quot;1&quot; > Admin</OPTION>
<OPTION value=&quot;2&quot; > Maintainer</OPTION>
<OPTION value=&quot;3&quot; > User</OPTION>
</body></html>

Thank you very much for your time and I am really appreciated your help

John
 
John,

I think it's easier to just do it with ASP on the server. Here, try this.
Code:
<%
dim var1
dim j
var1= request.querystring(&quot;id&quot;)
%>
<html>
<head>
</head>

<body>

<SELECT id=selectUsr name=selectUsr width=&quot;100%&quot; style=&quot;WIDTH: 199px&quot; >
<%
j = &quot;&quot;
IF var1 = &quot;0&quot; THEN
  j = &quot;selected&quot;
END IF
%>
<OPTION <%=j%> value=&quot;0&quot; > Select User Role</OPTION>
<%
j = &quot;&quot;
IF var1 = &quot;1&quot; THEN
  j = &quot;selected&quot;
END IF
%>
<OPTION value=&quot;1&quot; > Admin</OPTION>
<%
' AND SO ON AND SO FORTH
%>
<OPTION value=&quot;2&quot; > Maintainer</OPTION>
<OPTION value=&quot;3&quot; > User</OPTION>
</body></html>

Now if you're writing this select list statically, I mean if you're not pulling these values from a database that convention could get a little tedious. Even then, there is a client side solution, but you must use JavaScript instead of VBScript on the client side if you want it to be able to work with netscape.

The above example works. Let me know if you want the JavaScript equivalant anyways.

ToddWW
 
Hi ToddWW,

Thank you for your quick reply. I am really apreciated.
Sorry to bother you again but I still don't make it works.
If you have time, please send me the javascript code for client side version.

Thank you very much.

<%
dim var1
dim j
var1= request.querystring(&quot;id&quot;)
'I try to print the value of var1 here and it work
'(for testing purpose)
response.write var1
'the var1 is 1
%>
'but I can't get the var1 value below. I have no idea
<html>
<head>
</head>

<body>

<SELECT id=selectUsr name=selectUsr width=&quot;100%&quot; style=&quot;WIDTH: 199px&quot; >
<%
j = &quot;&quot;
IF var1 = &quot;0&quot; THEN
j = &quot;selected&quot;
END IF
%>
<OPTION <%=j%> value=&quot;0&quot; > Select User Role</OPTION>
<%
j = &quot;&quot;

'I use this
response.write var1
' to test the var1 but it does not print anything.
' Therefore the IF statement not working properly.
'you have any idea.?

IF var1 = &quot;1&quot; THEN
j = &quot;selected&quot;
END IF
%>
<OPTION <%=j%> value=&quot;1&quot; > Admin</OPTION>
<%
' AND SO ON AND SO FORTH
%>
<OPTION value=&quot;2&quot; > Maintainer</OPTION>
<OPTION value=&quot;3&quot; > User</OPTION>
</body></html>

 
I'll try to help, if i understand what you wanted to do.

You just need to add:

<%
if var1=admin ' or whatever you call it
then
%>
<!-- this is in html-->
<option selected><%=var1%></option> <!--or <%var1%> not sure about the =

hope it will help
-->

 
It's there. If it showed up near the top of the page, then it's available at the bottom.

First of all, make sure you have the following two lines at the top of every ASP page.
Code:
<%@ Language=VBScript %>
<% Option Explicit %>

The option explicit is the most important because it will help identify errors in your variable assignments and will also require you to dim all of your variables first. It's a very good practice and helps with variable errors.

Now, try this small change.

dim var1
var1 = Trim(request.querystring(&quot;id&quot;))


Second, please change that variable name to something else besides var1. Maybe you can name it userrole

Show me exactly how / where you are issuing the Response.Write method near the select list where you say that it is returning nothing. Maybe past the whole darn page here.

ToddWW
 
John,

Take a look at my last reply. It has some very good tips on variable assignments, etc...

ToddWW
 
Hi ToddWW,

Thank you for all your good tips and help.
You have a nice day!

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top