|
equating a database record Posted: 30 Jan 2005
I) If u want to populate ur dropdown with reordset then use:- this is an examle where i populate poduct names into dropdown and use product id to any particular option's value. <select name="product"> <option value="">-----------------</option> <%Do while not rs.eof %> <option value="<%=rs("ProductID")%>"><%=rs("ProductName")%></option> <% rs.movenext Loop %> </select>
II) if u want to show any particular option selected onload then two options: First is using vbscript only:- use if statement <select name="product"> <option value="">-----------------</option> <%Do while not rs.eof %> <% if strprodid = rs("ProductId") then %> <option value="<%=rs("ProductID")%>" selected> <%=rs("ProductName")%> </option> <% else %> <option value="<%=rs("ProductID")%>"> <%=rs("ProductName")%> </option> <% end if rs.movenext Loop %> </select>
where strprodid contains product id which u want to select.it could be dynamically sent through querystring.
Secondly it could be done thro' javascript
function onload() { var i; var ind = document.frm.productid.value; for (i=0;i<document.frm.product.length;i++) { if(document.frm.product.options[i].value == ind) { document.frm.product.options[i].selected = true; } } } this function could be called at the loading of page in body tag. here productid is hidden text box containing dynamic value
i hope this information willl be useful
a computer graduate ,involved in asp too much
|