Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ASP / Database Access / May 2006



Tip: Looking for answers? Try searching our database.

Sending Extra Value to ComboBox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Prabhat - 22 May 2006 08:37 GMT
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
Anthony Jones - 22 May 2006 15:21 GMT
> Hi all,
>
[quoted text clipped - 17 lines]
>     <%else%>
>         <option

value="<%=oProductList.GetProduct(iCtr).ID%>"><%=oProductList.GetProduct(iCt
> r).Name%></option>
>     <%End If
[quoted text clipped - 5 lines]
> 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)
%>
   <option value="<%=oProd.ID%>" <%=SelectedText(oProd.ID, sProdID)%>
       version="<%=Server.HTMLEncode(oProd.Version)%>"
   ><%=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.
Prabhat - 22 May 2006 15:36 GMT
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:-
>
[quoted text clipped - 83 lines]
>
> Anthony.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.