473,326 Members | 2,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

accessing value of dynamic select box from vbscript runat=server

In a nutshell, I'm trying to dynamically create a select box with
ResultSet code in vbscript and then need to be able to access the value
of that select box later with a Save button.

I've got the select box filling with code similar to below:

<SCRIPT LANGUAGE=VBSCRIPT RUNAT=SERVER>
Public Sub BuildComboBox(rs, dispname, val, name, selected)
'rs = the recordset
'val = fieldname to place in the val of the option
'dispname = fieldname to display in the user control
'name = name of the select (cboBox)
'selected is the item in the lst that should be selected

rs.movefirst

response.write("<SELECT NAME=" & name & ">")

while not rs.eof
if rs.fields(val) = selected then
response.write("<OPTION VALUE=" & rs.fields(val) & " selected>")
response.write(rs.fields(dispname) & "</OPTION>")
else
response.write("<OPTION VALUE=" & rs.fields(val) & ">")
response.write(rs.fields(dispname) & "</OPTION>")
end if
rs.MoveNext
wend

response.write("</SELECT>")
End Sub

</SCRIPT>

Peachy. Now I need to get to the user-selected value of that box when
they hit the Save button. My issue with vbscript thus far is that
it'll create me a select box dynamically in the runat=server code (as
above). But another function in that same vbscript section can't find
my select box. It seems to only recognize it if I statically create it
in html, not in vbscript. Oh, and I'm using something like this in the
vbscript to get the select box's value: "dept =
DepartmentsSelectBox.Value"

Help? I've been cursing vbscript all day, and I'm sure my co-workers
are tired of my whining.

Mucho Thanks,
sara

Jun 21 '06 #1
7 13409
>> But another function in that same vbscript section can't find my select
box

Then, why didn't you show that code if that's where the problem is?
I'm sure my co-workers are tired of my whining.

So, stop whining.

Bob Lehmann

<sk****@gmail.com> wrote in message
news:11**********************@y41g2000cwy.googlegr oups.com... In a nutshell, I'm trying to dynamically create a select box with
ResultSet code in vbscript and then need to be able to access the value
of that select box later with a Save button.

I've got the select box filling with code similar to below:

<SCRIPT LANGUAGE=VBSCRIPT RUNAT=SERVER>
Public Sub BuildComboBox(rs, dispname, val, name, selected)
'rs = the recordset
'val = fieldname to place in the val of the option
'dispname = fieldname to display in the user control
'name = name of the select (cboBox)
'selected is the item in the lst that should be selected

rs.movefirst

response.write("<SELECT NAME=" & name & ">")

while not rs.eof
if rs.fields(val) = selected then
response.write("<OPTION VALUE=" & rs.fields(val) & " selected>")
response.write(rs.fields(dispname) & "</OPTION>")
else
response.write("<OPTION VALUE=" & rs.fields(val) & ">")
response.write(rs.fields(dispname) & "</OPTION>")
end if
rs.MoveNext
wend

response.write("</SELECT>")
End Sub

</SCRIPT>

Peachy. Now I need to get to the user-selected value of that box when
they hit the Save button. My issue with vbscript thus far is that
it'll create me a select box dynamically in the runat=server code (as
above). But another function in that same vbscript section can't find
my select box. It seems to only recognize it if I statically create it
in html, not in vbscript. Oh, and I'm using something like this in the
vbscript to get the select box's value: "dept =
DepartmentsSelectBox.Value"

Help? I've been cursing vbscript all day, and I'm sure my co-workers
are tired of my whining.

Mucho Thanks,
sara

Jun 22 '06 #2
sk****@gmail.com wrote:
In a nutshell, I'm trying to dynamically create a select box with
ResultSet code in vbscript and then need to be able to access the
value of that select box later with a Save button.

I've got the select box filling with code similar to below:

<SCRIPT LANGUAGE=VBSCRIPT RUNAT=SERVER>
Public Sub BuildComboBox(rs, dispname, val, name, selected)
'rs = the recordset
'val = fieldname to place in the val of the option
'dispname = fieldname to display in the user control
'name = name of the select (cboBox)
'selected is the item in the lst that should be selected

rs.movefirst

response.write("<SELECT NAME=" & name & ">")

while not rs.eof
if rs.fields(val) = selected then
response.write("<OPTION VALUE=" & rs.fields(val) & " selected>")
response.write(rs.fields(dispname) & "</OPTION>")
else
response.write("<OPTION VALUE=" & rs.fields(val) & ">")
response.write(rs.fields(dispname) & "</OPTION>")
end if
rs.MoveNext
wend

response.write("</SELECT>")
End Sub

</SCRIPT>

Peachy. Now I need to get to the user-selected value of that box when
they hit the Save button. My issue with vbscript thus far is that
it'll create me a select box dynamically in the runat=server code (as
above). But another function in that same vbscript section can't find
my select box. It seems to only recognize it if I statically create
it in html, not in vbscript. Oh, and I'm using something like this
in the vbscript to get the select box's value: "dept =
DepartmentsSelectBox.Value"


What have you tried (show us what you really have instead of "something
like" what you have).

It never hurts to give us a small repro page to play with. By "repro page" I
mean a page where nothing except the bits related to your problem exist.
Something like:

<html><body><form method="post">
<%
if request.form("cboBox")="" then
BuildComboBox
else
Response.write request.form("cboBox")
end if
Sub BuildComboBox()
response.write "<SELECT NAME=""cboBox"">"
dim i
for i = 68 to 75
response.write "<option value=""" & i & """>" & chr(i) & vbcrlf
next
response.write "</select>"
End Sub
%>
<br><input type="submit" value="Save">
</form></body></html>
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jun 22 '06 #3
Bob
Let me get this straight. In server side code you are creating a drop
down select box to be sent to the client. In the same server side code
you are trying to access the value of that select box before it is sent
to the client?

If you want the value selected you'll have to wait until the client
submits the form. Then in the page defined in the action parameter of
the form you can get the value using Request.Form("name of select
object").

HTH

Jun 22 '06 #4

Bob Barrows [MVP] wrote:
What have you tried (show us what you really have instead of "something
like" what you have).

It never hurts to give us a small repro page to play with. By "repro page" I
mean a page where nothing except the bits related to your problem exist.


Here's what I have, paired down for the sake of clarity:

<script LANGUAGE="VBScript" runat="server">
Protected Sub showDropDownList(ByVal table)

'-- SQL Statement
strSQL = "SELECT * FROM " & table & " ORDER BY 1"

'-- Execute our SQL statement and store the recordset
rs = con.Execute(strSQL)

'-- If we have records to return
If Not rs.EOF Then
'-- Open a form/select tag THE NAME OF THE SELECT IS
DEFINED HERE
Response.Write("<select name=" & table & "Select""
style=""width: 155px"" runat=""server"">")
Response.Write("<option selected=""selected""
value="""">Choose....</option>")

'-- loop and build each database entry as a selectable
option
While rs.EOF = False
Response.Write("<option value=" & rs.Fields(0).Value &
">" _
& rs.Fields(1).Value & "</option>")

'-- Move recordset to the next value
rs.movenext()
End While
End If
'--END OF MAIN CODE BLOCK

'-- close select/form tags
Response.Write("</select>")
End Sub

Public Sub SaveBtn_Click(ByVal sender As Object, ByVal e As
System.EventArgs)

' Setting variables
Dim sql_insert, sql_numrows, num_rows, rs
Dim account, upc, sku, plu, dept, ...etc
num_rows = 0

' Receiving values from Form (abbreviated list here..)
dept = AccountsSelect.Value <------ BECAUSE THE NAME
"AccountsSelect" IS CREATED IN THE CODE BLOCK ABOVE, I GET ERRORS HERE

sh_desc = ShDescText.Value
lg_desc = LgDescText.Value
is_active = ActiveRadioButtonList.SelectedItem.Value

' Creating the Connection Object and opening the database
con_str = "DRIVER={SQL Server};.....;"
con = Server.CreateObject("ADODB.Connection")
con.Open(con_str)

sql_insert = "some string i cut out to make this code block
shorter"
' Executing the sql insertion code
con.Execute(sql_insert)

' Done. Now Close the connection
con.Close()
con = Nothing

' load the list page
Response.Redirect("~/item_list.aspx")
End Sub
</script>

Also, for more information, if I create the select in HTML (as opposed
to creating it in the vbscript above), and then try to create the
'option' lines in the vbscript, the 'runat=server' line won't let me
type a select statement followed by script. e.g.,
<select size="1" id="subwork" name="subWorkCombo" runat="server">
<%
Call showDropDownList("UnitOfMeasureTypes")
%>
</select>

The code inside the script tags is never hit as long as I have the
"runat=server" prop in the select code. If I remove the
"runat=server", the select box name can't be accessed from the SaveBtn
sub.

Thank you all so much for the quick replies!
sara

Jun 22 '06 #5

Bob Barrows [MVP] wrote:
What have you tried (show us what you really have instead of "something
like" what you have).

It never hurts to give us a small repro page to play with. By "repro page" I
mean a page where nothing except the bits related to your problem exist.


Here's what I have, paired down for the sake of clarity:

<script LANGUAGE="VBScript" runat="server">
Protected Sub showDropDownList(ByVal table)

'-- SQL Statement
strSQL = "SELECT * FROM " & table & " ORDER BY 1"

'-- Execute our SQL statement and store the recordset
rs = con.Execute(strSQL)

'-- If we have records to return
If Not rs.EOF Then
'-- Open a form/select tag THE NAME OF THE SELECT IS
DEFINED HERE
Response.Write("<select name=" & table & "Select""
style=""width: 155px"" runat=""server"">")
Response.Write("<option selected=""selected""
value="""">Choose....</option>")

'-- loop and build each database entry as a selectable
option
While rs.EOF = False
Response.Write("<option value=" & rs.Fields(0).Value &
">" _
& rs.Fields(1).Value & "</option>")

'-- Move recordset to the next value
rs.movenext()
End While
End If
'--END OF MAIN CODE BLOCK

'-- close select/form tags
Response.Write("</select>")
End Sub

Public Sub SaveBtn_Click(ByVal sender As Object, ByVal e As
System.EventArgs)

' Setting variables
Dim sql_insert, sql_numrows, num_rows, rs
Dim account, upc, sku, plu, dept, ...etc
num_rows = 0

' Receiving values from Form (abbreviated list here..)
dept = AccountsSelect.Value <------ BECAUSE THE NAME
"AccountsSelect" IS CREATED IN THE CODE BLOCK ABOVE, I GET ERRORS HERE

sh_desc = ShDescText.Value
lg_desc = LgDescText.Value
is_active = ActiveRadioButtonList.SelectedItem.Value

' Creating the Connection Object and opening the database
con_str = "DRIVER={SQL Server};.....;"
con = Server.CreateObject("ADODB.Connection")
con.Open(con_str)

sql_insert = "some string i cut out to make this code block
shorter"
' Executing the sql insertion code
con.Execute(sql_insert)

' Done. Now Close the connection
con.Close()
con = Nothing

' load the list page
Response.Redirect("~/item_list.aspx")
End Sub
</script>

Also, for more information, if I create the select in HTML (as opposed
to creating it in the vbscript above), and then try to create the
'option' lines in the vbscript, the 'runat=server' line won't let me
type a select statement followed by script. e.g.,
<select size="1" id="subwork" name="subWorkCombo" runat="server">
<%
Call showDropDownList("UnitOfMeasureTypes")
%>
</select>

The code inside the script tags is never hit as long as I have the
"runat=server" prop in the select code. If I remove the
"runat=server", the select box name can't be accessed from the SaveBtn
sub.

Thank you all so much for the quick replies!
sara

Jun 22 '06 #6
sk****@gmail.com wrote:
Bob Barrows [MVP] wrote:
What have you tried (show us what you really have instead of
"something like" what you have).

It never hurts to give us a small repro page to play with. By "repro
page" I mean a page where nothing except the bits related to your
problem exist.
Here's what I have, paired down for the sake of clarity:


You are definitely confused between classic ASP and ASP.Net. These are
two totally different technologies.
You are mixing vbscript (all variables are variants, adodb objects) with
vb.net (all variables have datatypes, recordsets don't exist, etc.
etc.) - not a good idea.

Go back to the books and decide which technology you are going to use.

If you decide on classic asp with vbscript, then things like
Public Sub SaveBtn_Click(ByVal sender As Object, ByVal e As
System.EventArgs)


are not supported. For one thing, you see those "As ..." expressions?
Those will cause an error in vbscript. For another, there are no
server-side events in classic ASP: the only information about a request
that is available to server-side code is contained in the Request
collections.
BTW, if you decide to go with classic ASP/vbscript, then go back and
look at the repro page I posted ... it works. Try it and see.

If you need to use .Net server-side events, then you need to use asp.net
and either vb.net or C# (or whatever other managed language suits your
fancy). For asp.net support go to
microsoft.public.dotnet.framework.aspnet

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jun 22 '06 #7
Thanks so much for the clarification. I'm a java (language, script,
servlet) person, and I let VisualStudio give me what it could for
"free" when making these asp pages. So, yeah, I'm new to this flavor
of pages. I'll come back to this with a fresh mind and better
direction.

Thanks Much,
sara
Bob Barrows [MVP] wrote:
sk****@gmail.com wrote:
Bob Barrows [MVP] wrote:
What have you tried (show us what you really have instead of
"something like" what you have).

It never hurts to give us a small repro page to play with. By "repro
page" I mean a page where nothing except the bits related to your
problem exist.


Here's what I have, paired down for the sake of clarity:


You are definitely confused between classic ASP and ASP.Net. These are
two totally different technologies.
You are mixing vbscript (all variables are variants, adodb objects) with
vb.net (all variables have datatypes, recordsets don't exist, etc.
etc.) - not a good idea.

Go back to the books and decide which technology you are going to use.

If you decide on classic asp with vbscript, then things like
Public Sub SaveBtn_Click(ByVal sender As Object, ByVal e As
System.EventArgs)


are not supported. For one thing, you see those "As ..." expressions?
Those will cause an error in vbscript. For another, there are no
server-side events in classic ASP: the only information about a request
that is available to server-side code is contained in the Request
collections.
BTW, if you decide to go with classic ASP/vbscript, then go back and
look at the repro page I posted ... it works. Try it and see.

If you need to use .Net server-side events, then you need to use asp.net
and either vb.net or C# (or whatever other managed language suits your
fancy). For asp.net support go to
microsoft.public.dotnet.framework.aspnet

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


Jun 22 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Matt | last post by:
If I assign VBScript server side variable a to javascript variable x, it is fine. <% Dim a, b a = 10 %> var x = <%= a %>; alert(x); But if I do the other way around, then it has 500 error....
1
by: Gary Bagen | last post by:
Hello, I am working on a page transition scheme and was wondering what the quickest way is to find out which ASP.NET controls need to be inside a form with runat=server. I've determined that...
0
by: J. Muenchbourg | last post by:
I'm trying to get a record to show on an aspx webpage with a classic asp reference: <%= rs("productname") %> ..but the displaying result shows the namespace(?¿) reference instead: ...
4
by: Matthew Louden | last post by:
It happend to me more than once. When I create web controls or move the positions in VS.NET, I encountered the following run-time errors: It doesn't matter what controls I create, the following...
3
by: ADavidson | last post by:
I'm getting a {"Parser Error: The Runat attribute must have the value Server." } error when I try to get the Server.GetlastError() in the Global.asax codebehind. Why am I getting this? I...
3
by: Russ | last post by:
I have a usercontrol that is loaded by a webform. The usercontrol populates a datagrid which users need the capability to export data from the grid to Excel. The problem is that when I attempt to...
4
by: Alex Maghen | last post by:
I have a master page which contains a general page framework and also contains a <form runat=server> around most of the content of the page. Inside that <form> tag is a ContentPlaceholder. I...
0
by: davidr | last post by:
Hi, I have a panel that I load user Control in no problem. The problem arrises when I do a post back on one of these user controls. I have button it does a click event. In this click event I...
4
by: John Kotuby | last post by:
Hi all, I am using a Repeater in conjunction with a SQLDatasource and SQL Server. One of the controls in the repeater is a HyperlLink as follows: <asp:HyperLink...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.