Link to home
Create AccountLog in
ASP

ASP

--

Questions

--

Followers

Top Experts

Avatar of beachcomp
beachcomp

Passing multiple values in a form
Hello,

Writing a form in ASP, and I need to have a single drop down in it.
However, I need to pass multiple values with it.
It posts to a mail page.

For example, the user select Option A from the drop down example below:

      <select size="1" name="DropDown">
      <option ValueA="1" ValueB="2" ValueC="3">A</option>
      <option>B</option>
      </select>

What I need to get in my mail script is:


<input type="hidden" name="ValueA" value="<%= request.form("DropDown") %>">
<input type="hidden" name="ValueB" value="<%= request.form("DropDown") %>">
<input type="hidden" name="ValueC" value="<%= request.form("DropDown") %>">


Is there any way to go about doing this?

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of sajukssajuks

<%

<input type="hidden" name="ValueA" value="<%=split(Request.Form("DropDown"), " "%>">
<input type="hidden" name="ValueB" value="<%=split(Request.Form("DropDown"), " "%>">
<input type="hidden" name="ValueC" value="<%=split(Request.Form("DropDown"), " "%>">

%>

I don't *think* it can be done exactly like that, however you could simply do something like:

<select size="1" name="DropDown">
     <option value="1|2|3">A</option>
     <option value="1|4|6">B</option>
     </select>


<%dim arr_dropdown
arr_dropdown = split(Request.Form("DropDown"), "|")
if isarray(arr_dropdown) then
%><input type="hidden" name="ValueA" value="<%= arr_dropdown(0)%>">
<input type="hidden" name="ValueB" value="<%= arr_dropdown(1)%>">
<input type="hidden" name="ValueC" value="<%= arr_dropdown(2)%>">
<%else
'chuck a poo
end if%>

Avatar of mattisflonesmattisflones🇺🇸

Hi beachcomp,
<select size="1" name="DropDown">
     <option Value="1:2:3">A</option>
     <option>B</option>
     </select>

then use something like this in the next page..
<%
dim myvar
dim a
dim b
dim c
myvar=split(request.form("dropdown",":"))
a=myvar(0)
b=myvar(1)
c=myvar(2)

and
<input type="hidden" name="ValueA" value="<%=(a)%>">
<input type="hidden" name="ValueB" value="<%=(b)%>">
<input type="hidden" name="ValueC" value="<%=(c)%>">

%>


Mattis

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


whoops:

replace split(Request.Form("DropDown"), " ") with

split(Request.Form("DropDown"), ",")

ASKER CERTIFIED SOLUTION
Avatar of codestormcodestorm

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of beachcompbeachcomp

ASKER

Thank you all but codestorm had the first working answer.

Thanks again!

I tried the solution but keep getting errors. My shopcart needs three values when I select an object in the dropdown box. Price, ProductID and ProductName. I might have placed it wrong in my ASP code.

The current setup gives me this error:

Microsoft VBScript runtime error '800a0009'
Subscript out of range: '[number: 0]'
/configframe.asp, line 58

This is line 58:
<input type="hidden" name="Price" value="<%=arr_dropdown(0)%>">

Can anyone locate my problem ? (The dropdown box shows up fine above the error message)



<body>

<form method="GET" action="shopcart.asp" target="_self">
<select name="Dropdown">"
<%
strDSN = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("/database/hovedmenu.mdb")
Set myCon = Server.CreateObject("ADODB.Connection")
myCon.Open strDSN

Varenr = request.querystring("varenr")

SQL = "SELECT (SELECT pris  FROM produkter where config.varenr=produkter.varenr) AS Prispc, (SELECT varenavn  FROM produkter WHERE varenr=kabinet) AS Kabinet, (SELECT pris  FROM produkter where varenr=kabinet) AS Priskabinet, (SELECT pris FROM produkter WHERE varenr=xkabinet) AS Prisxkabinet, (SELECT Varenr FROM produkter where varenr=kabinet) AS Varenrkabinet FROM Produkter INNER JOIN Config ON Produkter.Varenr=Config.Varenr WHERE Config.Varenr='" & varenr & "' AND (SELECT webstatus FROM produkter WHERE varenr=kabinet)='www'"

Set rs = mycon.Execute(SQL)

If not (rs.BOF or rs.EOF) Then

Response.Write "Pris før ændringer: Kr. " & rs("prispc")*1.25 & ",00" & " ( " & FormatNumber(rs("prispc"),2) & " )" & "<BR>" & "<BR>"
Response.Write "Kabinet" & "<BR>"

response.write "<option selected>Vælg</option>"

Do while not rs.EOF

    prispc=rs("prispc")*1.25
    Prismoms = FormatNumber(((rs("priskabinet")-rs("prisxkabinet"))*1.25),2)
    Prismomsex = FormatNumber(rs("priskabinet")-rs("prisxkabinet"),2)
    kabinet = rs("kabinet")
    varenrkabinet = rs("Varenrkabinet")

%>
<option value="1|2|3"><%=rs("kabinet")%> <%=Prismoms%> ( <%=Prismomsex%> )</option>
<%

rs.movenext
loop

Else

Response.write "No upgrades available."

End if
%>

<%
dim arr_dropdown
arr_dropdown = split(Request.Form("Dropdown"), "|")
if isarray(arr_dropdown) then
%>

<input type="hidden" name="Price" value="<%=arr_dropdown(0)%>">
<input type="hidden" name="ProductID" value="<%=arr_dropdown(1)%>">
<input type="hidden" name="ProductName" value="<%=arr_dropdown(2)%>">

<input type="hidden" name="Quantity" value="1">
<input type="hidden" name="Action" value="AddItem">
<input type="submit" value="Send"><input type="reset" value="Nulstil" name="B2">

<%
else
'chuck a wobbly
end if
%>

</select>
</form>
</body>

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Hmm, OK. Let's debug. On line 57 (or the line above the error, anyhow) put:

Response.write "("
Response.write Request.Form("Dropdown")
Response.write ")"

and we'll see what that outputs.

I tried to put it in both with <% %> and without just about everywhere in the code with absolutely no change in the output at all.

Hmmm. Could you perhaps post a link to the zipped file(s) in question, so we can pore over the entire source(s)?

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


http://www.etotal.dk/xpex/code.zip

Infoframe.asp which shows a specific product, in this case a computer sends varenr (it's ProductID) to configframe.asp. Configframe.asp looks in the database for the upgrade options on this varenr (ProductID) and lists the products in a dropdown box.

Now, in infoframe.asp it is easy to send the values Quantity, Price, ProductID and ProductName to shopcart.asp because there are only one product.

My problem:
In configframe.asp there are several products listet in the dropdown box and the right values need to be sent for the selected product. And I am trying to get a SEND-button, not an onchange thing.

Shopcart.asp receives like this:
<%
If Action="AddItem" then
    ProductID=Request.QueryString("ProductID")
    ProductName=Request.QueryString("ProductName")
    Quantity=Request.QueryString("Quantity")
    Price=Request.QueryString("Price")
...

Hmm, the zip file isn't there, so will have to guess a bit.

From your page names I assume you're using a frameset to place them all?

When posting the dropdown data, do you:

1) Have the dropdown within the <form></form> tags of the form being posted?
2) Have something in the form like
target="target_frame" ?
ASP

ASP

--

Questions

--

Followers

Top Experts

Active Server Pages (ASP) is Microsoft’s first server-side engine for dynamic web pages. ASP’s support of the Component Object Model (COM) enables it to access and use compiled libraries such as DLLs. It has been superseded by ASP.NET, but will be supported by Internet Information Services (IIS) through at least 2022.