Solved

How to change the selectbox to text field.

Posted on 2004-10-04
6
269 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

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

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

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

Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

622 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