473,545 Members | 937 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=VBSCRI PT RUNAT=SERVER>
Public Sub BuildComboBox(r s, 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(dispn ame) & "</OPTION>")
else
response.write( "<OPTION VALUE=" & rs.fields(val) & ">")
response.write( rs.fields(dispn ame) & "</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 =
DepartmentsSele ctBox.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 13427
>> 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.c om> wrote in message
news:11******** **************@ y41g2000cwy.goo glegroups.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=VBSCRI PT RUNAT=SERVER>
Public Sub BuildComboBox(r s, 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(dispn ame) & "</OPTION>")
else
response.write( "<OPTION VALUE=" & rs.fields(val) & ">")
response.write( rs.fields(dispn ame) & "</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 =
DepartmentsSele ctBox.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.co m 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=VBSCRI PT RUNAT=SERVER>
Public Sub BuildComboBox(r s, 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(dispn ame) & "</OPTION>")
else
response.write( "<OPTION VALUE=" & rs.fields(val) & ">")
response.write( rs.fields(dispn ame) & "</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 =
DepartmentsSele ctBox.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><fo rm method="post">
<%
if request.form("c boBox")="" then
BuildComboBox
else
Response.write request.form("c boBox")
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("n ame 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="VBScr ipt" runat="server">
Protected Sub showDropDownLis t(ByVal table)

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

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

'-- 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=""sele cted""
value="""">Choo se....</option>")

'-- loop and build each database entry as a selectable
option
While rs.EOF = False
Response.Write( "<option value=" & rs.Fields(0).Va lue &
">" _
& rs.Fields(1).Va lue & "</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(B yVal sender As Object, ByVal e As
System.EventArg s)

' 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.Valu e
lg_desc = LgDescText.Valu e
is_active = ActiveRadioButt onList.Selected Item.Value

' Creating the Connection Object and opening the database
con_str = "DRIVER={SQ L Server};.....;"
con = Server.CreateOb ject("ADODB.Con nection")
con.Open(con_st r)

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.Redire ct("~/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="subWorkCo mbo" runat="server">
<%
Call showDropDownLis t("UnitOfMeasur eTypes")
%>
</select>

The code inside the script tags is never hit as long as I have the
"runat=serv er" prop in the select code. If I remove the
"runat=serv er", 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="VBScr ipt" runat="server">
Protected Sub showDropDownLis t(ByVal table)

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

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

'-- 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=""sele cted""
value="""">Choo se....</option>")

'-- loop and build each database entry as a selectable
option
While rs.EOF = False
Response.Write( "<option value=" & rs.Fields(0).Va lue &
">" _
& rs.Fields(1).Va lue & "</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(B yVal sender As Object, ByVal e As
System.EventArg s)

' 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.Valu e
lg_desc = LgDescText.Valu e
is_active = ActiveRadioButt onList.Selected Item.Value

' Creating the Connection Object and opening the database
con_str = "DRIVER={SQ L Server};.....;"
con = Server.CreateOb ject("ADODB.Con nection")
con.Open(con_st r)

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.Redire ct("~/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="subWorkCo mbo" runat="server">
<%
Call showDropDownLis t("UnitOfMeasur eTypes")
%>
</select>

The code inside the script tags is never hit as long as I have the
"runat=serv er" prop in the select code. If I remove the
"runat=serv er", 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.co m 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(B yVal sender As Object, ByVal e As
System.EventArg s)


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.publi c.dotnet.framew ork.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.co m 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(B yVal sender As Object, ByVal e As
System.EventArg s)


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.publi c.dotnet.framew ork.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
8320
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. any ideas??
1
1649
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 asp:Label does not need to have the form runat=server and that asp:Textbox requires it. Thanks, Gar
0
845
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: System.__ComObject ..i'm unsure of the asp: runat=server coding to use for this simple
4
9945
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 'checkbox' control is just an example. Control 'CheckBox1' of type 'CheckBox' must be placed inside a form tag with runat=server. Description: An...
3
6032
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 tried to remove the code-behind and add the <script language="C#" runat="server"> but that fails as well. The code is simply:
3
4171
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 export the data to excel I get the following error message: Control 'RoomReservationReport1_dgReservations__ctl2__ctl0' of type...
4
13309
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 then create an ASPX which is tied to that MasterPage and in it a put a bunch of form fields and an <asp:Button />. When I try to run the page, I get......
0
3403
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 will do some database updates, then I will use reflection to call a method in the parent (this.page) to load the new user control. Its at this...
4
9047
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 NavigateUrl='Search.aspx?page=base&amp;searchid=<% Eval("sequence")%>' ..... As you can see I am trying to pass a QueryString evaluated at runtime. All the other Evals of DataFields...
0
7807
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7419
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7756
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5326
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3442
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
703
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.