Solved

How to change the selectbox to text field.

Posted on 2004-10-04
6
267 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Migrating to Exchange 2013 4 57
Display recordset field HTML encoded 21 57
Lines Not Lining Up 2 98
Problem to Popup 2 97
Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
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 …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 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