Sending Extra Value to ComboBox

P

Prabhat

Hi all,

I have one combobox where I want to display Name of the Products that are
loaded in the collection object. But I am able to send only ID and Name of
the Product where ID is the value of the option tag and products name is the
display text for option tag. I want to send the Product Version Number to
clients browser for ALL Products that are loaded to combobox so that On
Change of the combobox the Version Number should display in one of the Edit
Box. How can I do that?

Code fragment that loads the Products to ComboBox:

<%sProductID = Request("cmbProduct")%>
<select name="cmbProduct">
<option value="NULL" selected>Select a Product</option>
<%For iCtr = 1 to oProductList.Count
If CStr(oProductList.GetProduct(iCtr).ID) = sProductID Then%>
<option value="<%=oProductList.GetProduct(iCtr).ID%>"
selected><%=oProductList.GetProduct(iCtr).Name%></option>
<%else%>
<option
value="<%=oProductList.GetProduct(iCtr).ID%>"><%=oProductList.GetProduct(iCt
r).Name%></option>
<%End If
Next
Set oProductList = Nothing %>

Please suggest.

Thanks in advance
Prabhat
 
A

Anthony Jones

Prabhat said:
Hi all,

I have one combobox where I want to display Name of the Products that are
loaded in the collection object. But I am able to send only ID and Name of
the Product where ID is the value of the option tag and products name is the
display text for option tag. I want to send the Product Version Number to
clients browser for ALL Products that are loaded to combobox so that On
Change of the combobox the Version Number should display in one of the Edit
Box. How can I do that?

Code fragment that loads the Products to ComboBox:

<%sProductID = Request("cmbProduct")%>
<select name="cmbProduct">
<option value="NULL" selected>Select a Product</option>
<%For iCtr = 1 to oProductList.Count
If CStr(oProductList.GetProduct(iCtr).ID) = sProductID Then%>
<option value="<%=oProductList.GetProduct(iCtr).ID%>"
selected><%=oProductList.GetProduct(iCtr).Name%></option>
<%else%>
<option
value= said:
r).Name%></option>
<%End If
Next
Set oProductList = Nothing %>

Please suggest.

Thanks in advance
Prabhat

Here is a mock up:-

<%

Class CProd
Public Name
Public ID
Public Version
End Class

Class CList
Public Count
Public GetProduct
Private Sub Class_Initialize()
Count = 3
ReDim GetProduct(3)
Set GetProduct(1) = New CProd
Set GetProduct(2) = New CProd
Set GetProduct(3) = New CProd
GetProduct(1).ID = 1
GetProduct(2).ID = 2
GetProduct(3).ID = 3
GetProduct(1).Name = "First"
GetProduct(2).Name = "Second"
GetProduct(3).Name = "Third"
GetProduct(1).Version = "1.0"
GetProduct(2).Version = "1.1"
GetProduct(3).Version = "2.0"
End Sub
End Class

Dim oProductList: Set oProductList = New CList
Dim sProdID : sProdID = Request.QueryString("cmbProduct")

%>
<html>
<body>

<script type="text/javascript">

function cmdProduct_onchange()
{

document.getElementById('spnProdVer').innerHTML =
this.options[this.selectedIndex].getAttribute("version")

}
</script>

<select id="cboProd" name="cmbProduct"
onchange="cmdProduct_onchange.call(this)" >
<option <%=SelectedText("", sProdID)%> >Select a Product</option>
<%

Dim oProd

For iCtr = 1 to oProductList.Count
Set oProd = oProductList.GetProduct(iCtr)
%>
<%=Server.HTMLEncode(oProd.Name)%></option>
<%
Next

Function SelectedText(rsID, rsProdID)
If CStr(rsID) = rsProdID Then
SelectedText = "selected"
Else
SelectedText = ""
End If
End Function

Function VersionText(roList, rsProdID)
If rsProdID <> "" Then
VersionText = roList.GetProduct(Clng(rsProdID)).Version
End If
End Function
%>
</select>
<span class="version"
id="spnProdVer"><%=Server.HTMLEncode(VersionText(oProductList,
sProdID))%></span>
</body>
</html>


Anthony.
 
P

Prabhat

Hi Anthony,

It was great. Working as I expected. I never know about this technique in
ASP. Thanks for this. I will also study more on this

Thanks again
Prabhat


Here is a mock up:-

<%

Class CProd
Public Name
Public ID
Public Version
End Class

Class CList
Public Count
Public GetProduct
Private Sub Class_Initialize()
Count = 3
ReDim GetProduct(3)
Set GetProduct(1) = New CProd
Set GetProduct(2) = New CProd
Set GetProduct(3) = New CProd
GetProduct(1).ID = 1
GetProduct(2).ID = 2
GetProduct(3).ID = 3
GetProduct(1).Name = "First"
GetProduct(2).Name = "Second"
GetProduct(3).Name = "Third"
GetProduct(1).Version = "1.0"
GetProduct(2).Version = "1.1"
GetProduct(3).Version = "2.0"
End Sub
End Class

Dim oProductList: Set oProductList = New CList
Dim sProdID : sProdID = Request.QueryString("cmbProduct")

%>
<html>
<body>

<script type="text/javascript">

function cmdProduct_onchange()
{

document.getElementById('spnProdVer').innerHTML =
this.options[this.selectedIndex].getAttribute("version")

}
</script>

<select id="cboProd" name="cmbProduct"
onchange="cmdProduct_onchange.call(this)" >
<option <%=SelectedText("", sProdID)%> >Select a Product</option>
<%

Dim oProd

For iCtr = 1 to oProductList.Count
Set oProd = oProductList.GetProduct(iCtr)
%>
<%=Server.HTMLEncode(oProd.Name)%></option>
<%
Next

Function SelectedText(rsID, rsProdID)
If CStr(rsID) = rsProdID Then
SelectedText = "selected"
Else
SelectedText = ""
End If
End Function

Function VersionText(roList, rsProdID)
If rsProdID <> "" Then
VersionText = roList.GetProduct(Clng(rsProdID)).Version
End If
End Function
%>
</select>
<span class="version"
id="spnProdVer"><%=Server.HTMLEncode(VersionText(oProductList,
sProdID))%></span>
</body>
</html>


Anthony.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top