Solved

How to change the selectbox to text field.

Posted on 2004-10-04
6
264 Views
Last Modified: 2010-04-06
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>


0
Comment
Question by:Melfeky
6 Comments
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 12223303
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
0
 

Author Comment

by:Melfeky
ID: 12223573
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.
0
 
LVL 18

Expert Comment

by:arantius
ID: 12241371
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) %>">
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:Melfeky
ID: 12242114
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?
0
 
LVL 12

Expert Comment

by:sachitjain
ID: 12284357
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 %>
">
0
 
LVL 12

Accepted Solution

by:
sachitjain earned 200 total points
ID: 12284369
This would be more polished

<input type="text" name="Sub2categorySelect" value="
     <% If showSub2cat = true Then %>
              <% 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 %>
">
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Owl Carousel 6 235
how to extract window origin in spring 2 74
Adjust the position 3 65
Grunt Copy file to another destination. 1 56
It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to count occurrences of each item in an array.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question