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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

where is the error

Status
Not open for further replies.

cazeno

Technical User
Jun 30, 2000
23
0
0
DE
i want to get the values if one is selected in a listbox menu in a variable
but its not working...the variable is always empty....
here is the code

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>

<%@LANGUAGE=&quot;VBScript&quot;%>
<!-- #INCLUDE VIRTUAL=&quot;adovbs.inc&quot; -->



<form name=&quot;form1&quot;>
<select name=&quot;tablename&quot; size=&quot;4&quot;>
<option value=&quot;item&quot; selected>item</option>
<option value=&quot;cust&quot; >cust</option>
<option value=&quot;prod&quot; >prod</option>
<option value=&quot;site&quot; >site</option>
</select>
<%
DIM tablename

SELECT CASE Request.Form(&quot;item&quot;)
CASE Request.Form(&quot;item&quot;)
tablename = Request.Form(&quot;cust&quot;)
CASE Request.Form(&quot;cust&quot;)
tablename = Request.Form(&quot;prod&quot;)
CASE Request.Form(&quot;prod&quot;)
tablename = Request.Form(&quot;prod&quot;)
CASE Request.Form(&quot;site&quot;)
tablename = Request.Form(&quot;site&quot;)
END SELECT
%>
<input type=&quot;submit&quot; name=&quot;Button&quot; value=&quot;Submit&quot;>
</form>

<%
set myConnection = Server.CreateObject(&quot;ADODB.Connection&quot;)
myConnection.Open &quot;DSN=ph;UID=sa&quot;
SQLQuery = &quot;select * from &quot; & tablename
set RSTitleList = myConnection.Execute(SQLQuery)%>

<p>&nbsp;</p>
<table cellpadding=2 cellspacing=0 border=1>
<tr bgcolor=&quot;#cccccc&quot;>
<% for each field in RSTitleList.Fields %>
<th><%=field.Name%></th>
<% next %>
</tr>
<% WHILE NOT RSTitleList.EOF %>
<tr>
<% for each field in RSTitleList.Fields %>
<td><small><%=field.Value%></small></td>
<% next %>
</tr>
<%
RSTitleList.MoveNext
Wend
%>
</table>
</head>

please help dont know...what do to
caz [sig][/sig]
 
You should use :
SELECT CASE Request.Form(&quot;[red]tablename[/red]&quot;) instead of :
SELECT CASE Request.Form(&quot;[red]item[/red]&quot;)
 
but the other problem i have that i dont how to retrieve the value from the selected listbox......
i made it like that but nothing is happening at all
--------------------------------
Sub proc_onClick()
tablename = table.getValue()
SELECT CASE Request.Form(&quot;tablename&quot;)
CASE tablename = &quot;item&quot;
tablename = tablename
CASE tablename = &quot;cust&quot;
tablename = tablename
CASE tablename = &quot;prod&quot;
tablename = tablename
CASE tablename = &quot;site&quot;
tablename = tablename
break
END SELECT
End Sub
---------------------------
where table is now the name of the listbox in the form.....i dont how to get the value of the selected field...e.g. prod is selected how can i get the value????¿¿¿¿ [sig][/sig]
 
If you have the listbox named tablename, then
request.form(&quot;tablename&quot;) will return the value of whatever option has been selected:

Select case request.form(&quot;tablename&quot;)
case &quot;item&quot;
do something
case &quot;prod&quot;
do something else
----------------
and so on
end select
 
this is not returning anything maybe theres something wrong somewhere else i dont now. the first time my code looked nearly like that with the same result
if i DIM my_variable without giving it a value from the begging on there is an error cause the variableiis empty...
here again the code....i have to get this to run till tomorow
so
---------------------------------
<form name=&quot;f1&quot; method=&quot;get&quot; action=&quot;test.asp&quot;>
<select name=&quot;table&quot; size=&quot;4&quot;>
<option value=&quot;item&quot; selected>item</option>
<option value=&quot;cust&quot; >cust</option>
<option value=&quot;prod&quot; >prod</option>
<option value=&quot;site&quot; >site</option>
</select>
<%
DIM RSTitleList
DIM tablename
tablename = &quot;cust&quot;
Sub proc_onClick()
Request.Form(&quot;f1.table&quot;)
SELECT CASE Request.Form(&quot;table&quot;)
CASE &quot;item&quot;
tablename = Request.Form(&quot;item&quot;)

CASE &quot;cust&quot;
tablename = Request.Form(&quot;cust&quot;)

CASE &quot;prod&quot;
tablename = Request.Form(&quot;prod&quot;)

CASE &quot;site&quot;
tablename = Request.Form(&quot;site&quot;)
break
END SELECT
End Sub

set myConnection = Server.CreateObject(&quot;ADODB.Connection&quot;)
myConnection.Open &quot;DSN=ph;UID=sa&quot;
SQLQuery = &quot;select * from &quot;& tablename
set RSTitleList = myConnection.Execute(SQLQuery)
%>
<input type=&quot;submit&quot; name=&quot;proc&quot; value=&quot;Submit&quot; onClick=&quot;proc_onClick&quot;>
</form>
<p>&nbsp;</p>
<table cellpadding=2 cellspacing=0 border=1>
<tr bgcolor=&quot;#cccccc&quot;>
<% for each field in RSTitleList.Fields %>
<th><%=field.Name%></th>
<% next %>
</tr>
<% WHILE NOT RSTitleList.EOF %>
<tr>
<% for each field in RSTitleList.Fields %>
<td><small><%=field.Value%></small></td>
<% next %>
</tr>
<%
RSTitleList.MoveNext
Wend
%>
------------------------------------
caz [sig][/sig]
 
I think you're getting confused at the point where you need to pass the value of selected option. Here's the simple code which works. You just thoroughly look at the way form's elements are named and referenced in the code; especially listbox and option elements of listbox.
Copy and save the following code as test.asp

<%@language=vbscript%>
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<TITLE></TITLE>
</HEAD>
<BODY>

<%
if len(request(&quot;tablename&quot;)) > 0 then
Response.Write request(&quot;tablename&quot;)
end if
%>

<form name=&quot;f1&quot; method=&quot;post&quot; action=&quot;test.asp&quot;>
<select name=&quot;tablename&quot; size=&quot;4&quot;>
<option value=&quot;item&quot; selected>item</option>
<option value=&quot;cust&quot;>cust</option>
<option value=&quot;prod&quot;>prod</option>
<option value=&quot;site&quot;>site</option>
</select>
<input type=&quot;submit&quot;>
</form>

</BODY>
</HTML>


And one more thing -- if you use Form collection of Request object, you need to specify post in method attribute of a form: <form name=&quot;f1&quot; method=&quot;post&quot; action=&quot;test.asp&quot;>

Hope you'll get at least first results -- value of selected option.
 
no nothing :( mean nothing now he submits something...i understand the code above but i still dont know how to put this into the variable. if i click on my submit button HTTP Fehler 404 this comes up.
im no programmer and think this is the problem .... hmmmoh well
[sig][/sig]
 
Let's start from the very beginning.

1.From your code I assume that your asp page submits form's information to itself and form f1 and processing code are in the same page.
2. In order for you to be able to get the value of a particular element of a form, you need to refer to it as in following :
request.form(&quot;element_name&quot;)
3. In order for you to assign this value to a variable, you need to do this:
dim some_variable
some_variable = request.form(&quot;element_name&quot;)

4. If you have number of elements with the same name, then request.form(&quot;element_name&quot;) will refer to a collection of elements and will hold an array of all elements with the same name.
5. In your case you have a <select>element named tablename. And <select> element contains a collection of <option> elements, which actually provide values. So if you want to find out which <option> element of the <select> element has been selected, you check to see which value has been passed with request.form(&quot;tablename&quot;):

dim [red]table[/red]
[red]table[/red] = request.form(&quot;tablename&quot;)

One more time : tablename is the name of <select> element.




 
1) guestg was right! make method=post and action=&quot;<name of your asp page>&quot;
2) i assume you're using only one page and let's say it's name is &quot;sample.asp&quot;
3) you need to use <if..else..end if> statement to test if the request object has something on it after the user click the Submit button..
4) the code looks something like this

<%If Request(&quot;tablename&quot;)=&quot;&quot; Then%>

<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;sample.asp&quot;>
<select name=&quot;tablename&quot; size=&quot;4&quot;>
<option value=&quot;item&quot; selected>item</option>
<option value=&quot;cust&quot; >cust</option>
<option value=&quot;prod&quot; >prod</option>
<option value=&quot;site&quot; >site</option>
</select>
<input type=&quot;submit&quot; name=&quot;Button&quot; value=&quot;Submit&quot;>
</form>

<%Else

DIM tablename

tablename = Request.Form(&quot;tablename&quot;)
set myConnection = Server.CreateObject(&quot;ADODB.Connection&quot;)
myConnection.Open &quot;DSN=ph;UID=sa&quot;
SQLQuery = &quot;select * from &quot; & tablename
set RSTitleList = myConnection.Execute(SQLQuery)%>

...continue your codes here...

hope this helps you,
bhudz [sig]<p>Jun Nantes<br><a href=mailto:bhudz@junnantes.com>bhudz@junnantes.com</a><br><a href= Nantes Official Internet Site</a><br>[/sig]
 
thx to u both.... it works *g* im a little bit sorry for myself that i couldnt make it on my own..but its the first step.
caz [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top