Link to home
Start Free TrialLog in
Avatar of Melfeky
Melfeky

asked on

How to change the selectbox to text field.

Hello all experts,
i have this form which have 3 select box that populate dynamically from an access db, the third box gets the number of calories selected by the second box , all i need to do is change this selectbox to text field.
Check this link :
http://ccc.1asphost.com/kotty1234/Copy%20of%20Copy%20of%20crash/demoform.asp
And here is the code of the form:
<%
If request("Reset")="" then
    Category=Request("CategorySelect")
    subCategory=Request("subCategorySelect")
    sub2Category=Request("sub2CategorySelect")
else
    Category=""
    subCategory=""
    sub2Category=""
end if
dim ARR
If Category <> "" and Category <> "NONE" then
        Arr = split(Category,"|")
        CatChosen = Arr(0)
        MyRegion = Arr(1)
end if
 If subCategory <> "" and subCategory <> "NONE" then
        Arr = split(subCategory,"|")
        sub2CatChosen = Arr(0)
        MyCenter = Arr(1)
    End if
If sub2Category <> "" and sub2Category <> "NONE"then
        Arr = split(sub2Category,"|")
        sub3catChosen = Arr(0)
        MyProgram = Arr(1)
    End if
 'To show display - check if Category is not blank or unchanged
    '----------------------------------------------------
    If MyRegion <> "" and (Request("CategorySelect") = Request("CategorySelectOld")) Then
 'To show display - check if subCategory is unchanged
        '--------------------------------------------
        If Request("subCategorySelect") = Request("subCategorySelectOld") then

            'To show display - check if sub2Category is selected
            '--------------------------------------------
        If Request("sub2CategorySelect") <> "" AND Request("sub2CategorySelect") <> "NONE" then
                showDisplay = true
             End if
 End if
    else
    showDisplay = false
    End if
' create and open the connection to the database
' get the first list of categories
' convert the record set to an array and clean up
'---------------------------------------------------------------
Set catConn = Server.CreateObject("ADODB.Connection")
catConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("DB1.mdb")
Set catRS = catConn.Execute("SELECT regionID, Region FROM Region ORDER BY Region")
catRows = catRS.getRows
catRS.Close
Set catRS = nothing
'---------------------------------------------------------------
'Check for presence of first Category selection
'---------------------------------------------------------------
'Process input if found
'-------------------------------
showSubcat = False
If (CatChosen <> "" and catChosen <> "NONE") Then

CatChosen = CInt(CatChosen)
showSubcat = True

'get the list of subcategories for given category
'-----------------------------------------------------
Set subRS = catConn.Execute("SELECT * " & _
" FROM Center " & _
" WHERE Center.RegionID = " & CatChosen & _
" ORDER BY Center")
'convert the record set to an array
'-----------------------------------------------
subRows = subRS.getRows
subRS.Close
Set subRS = nothing
End If
'---------------------------------------------------------------
'Check for presence of second subCategory selection
showSub2cat = False
If (sub2catChosen <> "" and sub2catChosen <> "NONE") and _
(Request("CategorySelect") = Request("CategorySelectOld")) Then
sub2catChosen = CInt(sub2catChosen)
showSub2cat = True
'get the list of sub2categories for given category
'-----------------------------------------------
Set sub2RS = catConn.Execute("SELECT * " & _
" FROM Program " & _
" WHERE Program.CenterID = " & Sub2CatChosen & _
" ORDER BY Program")
'convert the record set to an array
'-----------------------------------------------
sub2Rows = sub2RS.getRows
sub2RS.Close
Set sub2RS = nothing
End If
' clean up
'------------------------
catConn.Close
Set catConn = nothing
'---------------------------------------------------------------
'Begin ouput to page
'Create a list box for each category or subcategory
'---------------------------------------------------------------
%>
<HTML>
<HEAD>
<TITLE>Multiple Dependent Lists</TITLE>
<SCRIPT LANGUAGE=javascript type=""text/javascript"">
<!--
function additem(){
     var objForm = document.forms[0];
     var objSel1 = objForm.elements['SubcategorySelect'];
     var objSel2 = objForm.elements['strSelect2'];
     var objsel3 = objForm.elements['total'];
       var objtot = objForm.elements['total'];
       var bolSelected = false;;
     for(i=0;i<objSel1.length;i++){
          if(objSel1.options[i].selected){
               intLength = objSel2.length;
               objSel2.options[intLength]=new Option;
               objSel2.options[intLength].value = objSel1.options[i].value;
               objSel2.options[intLength].text = objSel1.options[i].text ;
                bolSelected = true;
              }
     }
     if(!bolSelected){
     alert("You did not select anything!");
     }
}
//
function addallitems(){
     var objForm = document.forms[0];
     var objSel1 = objForm.elements['SubcategorySelect'];
     var objSel2 = objForm.elements['strSelect2'];
     for(i=0;i<objSel1.length;i++){
               intLength = objSel2.length;
               objSel2.options[intLength]=new Option;
               objSel2.options[intLength].value = objSel1.options[i].value;
               objSel2.options[intLength].text = objSel1.options[i].text ;
          }
     objSel1.options.length = 0;
}
function deleteItem(objSelect){
     var objSel = document.forms[0].elements[objSelect];
     var bolSelected;
     for(i=0;i<objSel.length;i++){
          if(objSel.options[i].selected){
               objSel.options[i]=null;
               bolSelected=true;
     i=-1;
          }
     }
     if(!bolSelected){
          alert("You did not select anything!");
     }
}
//
//-->
function selectAllItems(){
     var objForm = document.forms[0];
     var objSel2 = objForm.elements['strSelect2'];
       for(i=0;i<objSel2.length;i++){
              objSel2.options[i].selected = true;
       }
    return true;
}
</SCRIPT></HEAD>
<H2>&nbsp;</H2>
<br>
<b><font color="#669933">Your ultimate calorie counter that u would ever find
</font></b>
<P><FORM Name="DemoForm" Action="" Method=Post onSubmit = "return selectAllItems()">
<p>
   <SELECT Name="CategorySelect"  size="1"
onChange="selectAllItems();document.DemoForm.submit();">
 <OPTION Value="NONE">-- choose a Food Group--
      <% For cnum = 0 To UBound(catRows,2) %>
      <OPTION Value="<%= catRows(0,cnum) %>|<%= catRows(1,cnum) %>"
<% If catRows(0,cnum) = Cint(catChosen) Then %>
    SELECTED
<% End If %>
><%= catRows(1,cnum) %>
      <% Next %>
    </SELECT>
    <SELECT Name="SubcategorySelect"  Size="1"
onChange="selectAllItems();document.DemoForm.submit();">
      <% If showSubcat = false Then %>
      <OPTION Value="NONE"><--Please Select-->
      <% Else %>
      <OPTION Value="NONE">-- choose a Center--
      <% For cnum = 0 To UBound(subRows,2) %>
<OPTION Value="<%= subRows(0,cnum) %>|<%= subRows(2,cnum) %>"
<% If subRows(0,cnum) = Cint(sub2catChosen) Then %>
    SELECTED
     <% End If %>
        ><%= subRows(2,cnum) %>
      <% Next %>
      <% End If %>
    </SELECT>
    <select name="Sub2categorySelect"
onChange="selectAllItems();document.DemoForm.submit();"  size="1">
      <% If showSub2cat = false Then %>
      <option value="NONE">
      <% Else %>
      <option value="NONE">
      <% For cnum = 0 To UBound(sub2Rows,2) %>
      <option value="<%= sub2Rows(0,cnum) %>|<%= sub2Rows(3,cnum) %>"
<% If sub2Rows(0,cnum) = Cint(sub3catChosen) Then %>
    SELECTED
     <% End If %>
        ><%= sub2Rows(3,cnum) %>
      <% Next %>
      <% End If %>
    </select>
  </p>
  <p>
<INPUT type="button" value="Add Item" id=button1 name=button1 onClick="additem()">
    <INPUT type="button" value="Add all Items" id=button3 name=button3 onClick="addallitems()">
  <INPUT type="button" value="Remove Item" id=button4 name=button4 onClick="deleteItem('strSelect2')">
  </p<p>
    <select size=5  id=select2 name=strSelect2 multiple>
      <%
arrItems = split(Request.Form("strSelect2"),", ")
for i = 0 to UBound(arrItems)
   response.write("<option>" & arrItems(i) & "</option>" & VbCrLf)
next
%>
    </select>
    <input type="text" name="total" size="8">
  </p>
  <p>
    <Input Type="hidden" Name="CategorySelectOld" Value="<%=Request("CategorySelect")%>">
    <Input Type="hidden" Name="subCategorySelectOld" Value="<%=Request("subCategorySelect")%>">
  </p>
</FORM>
<%
If ShowDisplay=True then
    Response.Write (" <FONT color='#669933'  >There are " & MyProgram & " Calories in " & MyCenter & " .</FONT> <br>")
End if
%>
</BODY>
</HTML>


Avatar of VincentPuglia
VincentPuglia

To say the least, I'm confused.   I went to the site, the second selection list never filled.  And, I have no idea what this --> "all i need to do is change this selectbox to text field." <--  means

Vinny
Avatar of Melfeky

ASKER

sorry i was doing some tests, its working now , check it.
"all i need to do is change this selectbox to text field."  I mean  that i want the data displayed in the last select box to be displayed in a text field instead.
There's a bit too much information missing here.  But basically, instead of :

    <select name="Sub2categorySelect"
onChange="selectAllItems();document.DemoForm.submit();"  size="1">
     <% If showSub2cat = false Then %>
     <option value="NONE">
      <% Else %>
     <option value="NONE">
      <% For cnum = 0 To UBound(sub2Rows,2) %>
     <option value="<%= sub2Rows(0,cnum) %>|<%= sub2Rows(3,cnum) %>"
<% If sub2Rows(0,cnum) = Cint(sub3catChosen) Then %>
   SELECTED
    <% End If %>
       ><%= sub2Rows(3,cnum) %>
      <% Next %>
     <% End If %>
   </select>

Put:
<input type="text" name="Sub2categorySelect" value=""<%= sub2Rows(0,0)%>|<%= sub2Rows(3,0) %>">
Avatar of Melfeky

ASKER

Thanks arantius  , i replaced my code with urs,but i got this error:
Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'sub2Rows'
/select/demoform1.asp, line 277

You have said that there is  too much information missing, what information do u mean? and how could we solve this problem?
Try this

<input type="text" name="Sub2categorySelect" value="
     <% If showSub2cat = false Then %>
             <%= "" %>
     <% Else %>
             <% For cnum = 0 To UBound(sub2Rows,2) %>
                    <% If sub2Rows(0,cnum) = Cint(sub3catChosen) Then %>
                               <%= sub2Rows(0,cnum) %>|<%= sub2Rows(3,cnum) %>
                    <% End If %>
              <% Next %>
     <% End If %>
">
ASKER CERTIFIED SOLUTION
Avatar of sachitjain
sachitjain
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial