Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

disable combo box 1

Status
Not open for further replies.

mcpeekj

Vendor
Joined
Sep 21, 2001
Messages
105
I have a series of combo boxes that populate each other. I was wanting to have the current and previous boxes active, but any future boxes grayed out until it is their turn. I can't find anything on it. Can anybody help out?
 
Have your first combobox enable, the rest disable. Then before you populate the second combo, enable it first.

<select name="comb1" onchange="form1.comb2.disabled=false;populkateFnct();>
...

<select name="comb2" disabled">
...
 
Give each box a tab index so that the flow is correct when hitting the tab order
Code:
<select name='myfield' tabIndex='5' disabled onfocus='release();'>


write a js function using onfocus to open the new one
Code:
<script language='javascript'>
function release(){
  document.form1.myfield.disabled=false; 
}


Bastien

Cat, the other other white meat
 
I'm sorry, but that's not working for me. Here's my code, Make being the first box, Model being the 2nd:
<SELECT name="Make" onchange="form1.model.disabled=false";"submitMake()">
<%call makeMake%>
</SELECT>

I thought it might be the disabled=false, so I changed it to True, but that didn't work either. What am I missing?
 
Change

<SELECT name="Make" onchange="form1.model.disabled=false";"submitMake()">

to

<SELECT name="Make" onchange="form1.model.disabled=false;submitMake();">
 
Ok Kendel, I like your solution, but I've still got a problem. The page refreshes when a value is chosen, populating the next box. When that happens, the disabling on model overrides the enabling of model from make. That make sense? I appreciate the help
 
Put this in your header tags:

<SCRIPT LANGUAGE="JavaScript">
function dropdowns() {
if (document.form1.make.length > 0) {
document.form1.make.disabled = false;
}
else {
document.form1.make.disabled = true;
}
if (document.form1.model.length > 0) {
document.form1.model.disabled = false;
}
else {
document.form1.model.disabled = true;
}
}
</SCRIPT>

and this in the body tag:

onLoad="dropdowns()"

If there are items in the dropdown, it will be active, otherwise it will be inactive.
 
I don't know how do you populate one from the others. There are many ways to do this. You can use Bastien or mbrio's solutions. If you use mine, you can set setup some hidden field, before you submit the form, set the value of the hidden field then check these value when you load the form. Only set the comno disable when you get some values on the hidden fields ....
 
You can place this form1.model.disabled=false inside submitMake()

and have onChange="submitMake()" ...
 
Ok, I don't know why I'm having such a hard time with this. All relevant code is below. I'm thinking I need to disable the comboboxes in the ASP subs, but can't figure out how. Any ideas?
<%
dim strDataPath, strConnectString, objConnection, strMake, strModel, strYear, strEngine, strEngineSize, objRS, strSelected

strMake = Request.Form("Make")
strModel = Request.Form("Model")
strYear = Request.Form("Year")
strEngine = Request.Form("Engine")
strEngineSize = Request.Form("EngineSize")

'set connection strings for entire application
strDataPath = server.MapPath("NorthWind.mdb")
strConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;"_
+ " Data Source= " & strDataPath & ";"_
+ " Mode=Share Deny None;User Id=admin;PASSWORD=;"

if not IsObject("ojbConnection") then
set objConnection=Server.CreateObject("ADODB.Connection")
objConnection.ConnectionTimeout = 15
objConnection.CommandTimeout = 10
objConnection.Mode = 3 'adModeReadWrite
if objConnection.state = 0 then
objConnection.Open strConnectString
end if
end if

sub makeMake()
if not isObject("objRS") then
set objRS=Server.CreateObject("ADODB.RecordSet")
end if
if objRS.state <> 0 then
objRS.close
end if
objRS.Open "SELECT DISTINCT Make FROM tblInventory ORDER BY Make",objConnection,3,3
Response.Write("<option></option>" & VBCRLF )
do while not objRS.EOF
if objRS("Make") = strMake then
strSelected = " Selected "
else
strSelected = ""
end if
Response.Write("<option" & strSelected & ">" & objRS("Make") & "</option>" & VBCRLF )
objRS.MoveNext
loop
objRS.Close
set objRS=Nothing
end sub

sub makeModel()
if strMake <> "" then
if not isObject("objRS") then
set objRS=Server.CreateObject("ADODB.RecordSet")
end if
if objRS.state <> 0 then
objRS.close
end if
objRS.Open "SELECT DISTINCT Model FROM tblInventory WHERE Make = '" & strMake & "' ORDER BY Model",objConnection,3,3
if objRS.eof then
Response.Write("<option>No Models Found</option>")
else
Response.Write("<option>Select Model Now</option>" & VBCRLF )
do while not objRS.EOF
if objRS("Model") = strModel then
strSelected = " Selected "
else
strSelected = ""
end if
Response.Write("<option" & strSelected & ">" & objRS("Model") & "</option>" & VBCRLF )
objRS.MoveNext
loop
end if
objRS.Close
set objRS=Nothing
else
Response.Write("<option>Select a Make First</option>")
end if
end sub

sub makeYear()
if strModel <> "Select a Make First" AND strModel <> "Select Model Now" AND strModel <>"" then
if not isObject("objRS") then
set objRS=Server.CreateObject("ADODB.RecordSet")
end if
if objRS.state <> 0 then
objRS.close
end if
objRS.Open "SELECT DISTINCT Year FROM tblInventory WHERE Make = '"& strMake & "' AND Model = '" & strModel & "' ORDER BY Year",objConnection,3,3
if objRS.eof then
Response.Write("<option>No Years Found</option>")
else
Response.Write("<option>Select Year Now</option>" & VBCRLF )
do while not objRS.EOF
if objRS("Year") = strYear then
strSelected = " Selected "
else
strSelected = ""
end if
Response.Write("<option" & strSelected & ">" & objRS("Year") & "</option>" & VBCRLF )
objRS.MoveNext
loop
end if
objRS.Close
set objRS=Nothing
else
Response.Write("<option>Select a Model First</option>")
end if
end sub

sub makeEngine()
if strYear <> "Select a Year First" AND strYear <> "Select Year Now" AND strYear <>"" then
if not isObject("objRS") then
set objRS=Server.CreateObject("ADODB.RecordSet")
end if
if objRS.state <> 0 then
objRS.close
end if
objRS.Open "SELECT DISTINCT Engine FROM tblInventory WHERE Make = '"& strMake & "' AND Model = '" & strModel & "' AND Year = '" & strYear & "' ORDER BY Engine",objConnection,3,3
if objRS.eof then
Response.Write("<option>No Engine Found</option>")
else
Response.Write("<option>Select Engine Now</option>" & VBCRLF )
do while not objRS.EOF
if objRS("Engine") = strEngine then
strSelected = " Selected "
else
strSelected = ""
end if
Response.Write("<option" & strSelected & ">" & objRS("Engine") & "</option>" & VBCRLF )
objRS.MoveNext
loop
end if
objRS.Close
set objRS=Nothing
else
Response.Write("<option>Select a Year First</option>")
end if
end sub

sub makeEngineSize()
if strEngine <> "Select an Engine First" AND strEngine <> "Select Engine Now" AND strEngine <>"" then
if not isObject("objRS") then
set objRS=Server.CreateObject("ADODB.RecordSet")
end if
if objRS.state <> 0 then
objRS.close
end if
objRS.Open "SELECT DISTINCT EngineSize FROM tblInventory WHERE Make = '"& strMake & "' AND Model = '" & strModel & "' And Year = '" & strYear & "' AND Engine = '" & strEngine & "' ORDER BY EngineSize",objConnection,3,3
if objRS.eof then
Response.Write("<option>No Engine Found</option>")
else
Response.Write("<option>Select Engine Size Now</option>" & VBCRLF )
do while not objRS.EOF
if objRS("EngineSize") = strEngineSize then
strSelected = " Selected "
else
strSelected = ""
end if
Response.Write("<option" & strSelected & ">" & objRS("EngineSize") & "</option>" & VBCRLF )
objRS.MoveNext
loop
end if
objRS.Close
set objRS=Nothing
else
Response.Write("<option>Select an Engine First</option>")
end if
end sub
%>

<SCRIPT LANGUAGE=javascript>
<!--

function submitMake(){
var objForm = document.forms[0];
objForm.elements['model'].selectedIndex=0;
objForm.elements['year'].selectedIndex = 0;
objForm.elements['engine'].selectedIndex=0;
objForm.elements['engineSize'].selectedIndex = 0;
objForm.submit();
}
function submitModel(){
var objForm = document.forms[0];
objForm.elements['year'].selectedIndex = 0;
objForm.elements['engine'].selectedIndex=0;
objForm.elements['engineSize'].selectedIndex = 0;
objForm.submit();
}
function submitYear(){
var objForm = document.forms[0];
objForm.elements['engine'].selectedIndex = 0;
objForm.elements['engineSize'].selectedIndex = 0;
objForm.submit();
}
function submitEngine(){
var objForm = document.forms[0];
objForm.elements['engineSize'].selectedIndex=0;
objForm.submit();
}

function submitForm(){
var objForm = document.forms[0];
objForm.action = "viewlist.asp"
return true;
}

//-->
</SCRIPT>

</HEAD>
<BODY>
<FORM action="" method=POST id=form1 name=form1 onSubmit="return submitForm()">

<SELECT name="make" onchange="submitMake();">
<%call makeMake%>
</SELECT><br>
<SELECT name="model" onChange="submitModel()">
<%call makeModel%>
</SELECT><br>
<SELECT name="year" onChange="submitYear()">
<%call makeYear%>
</SELECT><br>
<SELECT name="engine" onChange="submitEngine()">
<%call makeEngine%>
</SELECT><br>
<SELECT name="engineSize">
<%call makeEngineSize%>
</SELECT>

<p><INPUT type="submit" value="Submit" id=submit1 name=submit1></p>
</FORM>
</BODY>
<%
objConnection.Close
set objConnection = Nothing
%>
 
change

<SELECT name="Make" onchange="form1.model.disabled=false;submitMake();">

to

<SELECT name="Make" onchange="form1.model.disabled=false;submitMake();return false;">

--Chessbot

The program didn't do anything wrong; it did exactly what you told it to!
 
Yeah, I'm not saying it's doing anything wrong, I'm just trying to get it to do what I want, which it isn't. How will adding return false help? Where am I disabling the box?
 
Ok, try this:

Code:
<SCRIPT LANGUAGE=javascript>
<!--

function submitMake(){
    var objForm = document.forms[0];
    [b]
    objForm.model.disabled=false;
    objForm.txtmodel.value="inactive";
    [/b]
    objForm.elements['model'].selectedIndex=0;
    objForm.elements['year'].selectedIndex = 0;
    objForm.elements['engine'].selectedIndex=0;
    objForm.elements['engineSize'].selectedIndex = 0;
    objForm.submit();
}
function submitModel(){
    var objForm = document.forms[0];
    [b]
    objForm.year.disabled=false;
    objForm.txtyear.value="inactive";
    [/b]
    objForm.elements['year'].selectedIndex = 0;
    objForm.elements['engine'].selectedIndex=0;
    objForm.elements['engineSize'].selectedIndex = 0;
    objForm.submit();
}
function submitYear(){
    var objForm = document.forms[0];
    [b]
    objForm.engine.disabled=false;
    objForm.txtengine.value="inactive";
    [/b]
    objForm.elements['engine'].selectedIndex = 0;
    objForm.elements['engineSize'].selectedIndex = 0;
    objForm.submit();
}
function submitEngine(){
    var objForm = document.forms[0];
    [b]
    objForm.engineSize.disabled=false;
    objForm.txtengineSize.value="inactive";
    [/b]
    objForm.elements['engineSize'].selectedIndex=0;
    objForm.submit();
}

function submitForm(){
    var objForm = document.forms[0];
    objForm.action = "viewlist.asp"
    return true;
}

//-->
</SCRIPT>

</HEAD>
<BODY>
<FORM action="" method=POST id=form1 name=form1 onSubmit="return submitForm()">

<SELECT  name="make" onchange="submitMake();">
    <%call  makeMake%>
</SELECT><br>
[b]<input type="hidden" name="txtmodel">[/b]
<SELECT  name="model" onChange="submitModel()" [b]<%If Request("txtmodel")="inactive" Then%>disabled<%End If%>[/b]>
    <%call makeModel%>
</SELECT><br>
[b]<input type="hidden" name="txtyear">[/b]
<SELECT  name="year" onChange="submitYear()" [b]<%If Request("txtyear")="inactive" Then%>disabled<%End If%>[/b]>
    <%call makeYear%>
</SELECT><br>
[b]<input type="hidden" name="txtengine">[/b]
<SELECT  name="engine" onChange="submitEngine()" [b]<%If Request("txtengine")="inactive" Then%>disabled<%End If%>[/b]>
    <%call makeEngine%>
</SELECT><br>
[b]<input type="hidden" name="txtengineSize">[/b]
<SELECT  name="engineSize" [b]<%If Request("txtengineSize")="inactive" Then%>disabled<%End If%>[/b]>
    <%call makeEngineSize%>
</SELECT>

<p><INPUT type="submit" value="Submit" id=submit1 name=submit1></p>
</FORM>
</BODY>
 
Thanks Kendel. That was very helpful. I didn't even think to post the javascript variable in the form for the ASP to read. That's probably why I had such a problem with it. After a couple of modifications on what you sent, I got exactly what I was looking for. Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top