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("Category Select")
subCategory=Request("subCa tegorySele ct")
sub2Category=Request("sub2 CategorySe lect")
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("subCategorySelect Old") then
'To show display - check if sub2Category is selected
'------------------------- ---------- ---------
If Request("sub2CategorySelec t") <> "" AND Request("sub2CategorySelec t") <> "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 .Connectio n")
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['Subcateg orySelect' ];
var objSel2 = objForm.elements['strSelec t2'];
var objsel3 = objForm.elements['total'];
var objtot = objForm.elements['total'];
var bolSelected = false;;
for(i=0;i<objSel1.length;i ++){
if(objSel1.options[i].sele cted){
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['Subcateg orySelect' ];
var objSel2 = objForm.elements['strSelec t2'];
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].selec ted){
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['strSelec t2'];
for(i=0;i<objSel2.length;i ++){
objSel2.options[i].selecte d = true;
}
return true;
}
</SCRIPT></HEAD>
<H2> </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.s ubmit();">
<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.s ubmit();">
<% 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.s ubmit();" 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('strSe lect2')">
</p<p>
<select size=5 id=select2 name=strSelect2 multiple>
<%
arrItems = split(Request.Form("strSel ect2"),", ")
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("Categor ySelect")% >">
<Input Type="hidden" Name="subCategorySelectOld " Value="<%=Request("subCate gorySelect ")%>">
</p>
</FORM>
<%
If ShowDisplay=True then
Response.Write (" <FONT color='#669933' >There are " & MyProgram & " Calories in " & MyCenter & " .</FONT> <br>")
End if
%>
</BODY>
</HTML>
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("Category
subCategory=Request("subCa
sub2Category=Request("sub2
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")
'To show display - check if subCategory is unchanged
'-------------------------
If Request("subCategorySelect
'To show display - check if sub2Category is selected
'-------------------------
If Request("sub2CategorySelec
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
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")
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['Subcateg
var objSel2 = objForm.elements['strSelec
var objsel3 = objForm.elements['total'];
var objtot = objForm.elements['total'];
var bolSelected = false;;
for(i=0;i<objSel1.length;i
if(objSel1.options[i].sele
intLength = objSel2.length;
objSel2.options[intLength]
objSel2.options[intLength]
objSel2.options[intLength]
bolSelected = true;
}
}
if(!bolSelected){
alert("You did not select anything!");
}
}
//
function addallitems(){
var objForm = document.forms[0];
var objSel1 = objForm.elements['Subcateg
var objSel2 = objForm.elements['strSelec
for(i=0;i<objSel1.length;i
intLength = objSel2.length;
objSel2.options[intLength]
objSel2.options[intLength]
objSel2.options[intLength]
}
objSel1.options.length = 0;
}
function deleteItem(objSelect){
var objSel = document.forms[0].elements
var bolSelected;
for(i=0;i<objSel.length;i+
if(objSel.options[i].selec
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['strSelec
for(i=0;i<objSel2.length;i
objSel2.options[i].selecte
}
return true;
}
</SCRIPT></HEAD>
<H2> </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()
<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()
<% 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()
<% 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('strSe
</p<p>
<select size=5 id=select2 name=strSelect2 multiple>
<%
arrItems = split(Request.Form("strSel
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("Categor
<Input Type="hidden" Name="subCategorySelectOld
</p>
</FORM>
<%
If ShowDisplay=True then
Response.Write (" <FONT color='#669933' >There are " & MyProgram & " Calories in " & MyCenter & " .</FONT> <br>")
End if
%>
</BODY>
</HTML>
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.
"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.s ubmit();" 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) %>">
<select name="Sub2categorySelect"
onChange="selectAllItems()
<% 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) %>">
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?
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 %>
">
<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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Vinny