473,406 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

A select drop-down that appears/disappears according to previous selection.

pk
Here is my code, and it's not working. Please help me get through
this. I've read every single tutorial and you may even see remnants of
some of their variables in my code. I don't know if I'm close, but I
feel that I'm getting there.

Thanks in advance for any help. I much appreciate it.

-pk

<SCRIPT>

function able(dropdown)
{
var myindex = dropdown.selectedIndex
if(myindex = 1) {
MMDiv.style.visibility='visible';
mainform.BalStep.focus();
}
else {
MMDiv.style.visibility='hidden';
}

</SCRIPT>

<Form Name="myform">
<tr>
<td height="7" width="177">
<div align="right"><font color="#000000" face="Comic Sans MS">Boring
Type:</font></div>
</td>
<td height="7" width="397"><div align="left"><font color=#000000
face="Comic Sans MS">

<select name=Finish onchange='able(this.form.Finish);'>
<option></option>
<option>Rough</option>
<option>Finish</option>
</select></font></div></td>

<DIV ID="MMDiv" style="visibility:hidden">
<LABEL FOR="BalStep">
<SELECT name=BalStepVal>
<option></option>
<option>Balanced Cutting</option>
<option>Step Cutting</option>
</SELECT>
</DIV>
</FORM>
</tr>

Aug 30 '05 #1
7 2027
Lee
pk said:

Here is my code, and it's not working. Please help me get through
this. I've read every single tutorial and you may even see remnants of
some of their variables in my code. I don't know if I'm close, but I
feel that I'm getting there.

Thanks in advance for any help. I much appreciate it.

-pk

<SCRIPT>

The SCRIPT tag requires a "type" attribute:

<script type="text/javascript">

function able(dropdown)
{
var myindex = dropdown.selectedIndex
if(myindex = 1) {
The "=" sign is the assignment operator, not the comparison
operator. You want:
if (myindex == 1) {
MMDiv.style.visibility='visible';
Don't refer to a page element by its ID value as if it were global.
It is in some browsers, but it's non-standard and poor practice.

document.getElementById("MMDiv").style.visibility= "visible";
mainform.BalStep.focus();

The same goes for forms, although they can be referred to as
attributes of the document, as in:

document.mainform.BalStep.focus();
<select name=Finish onchange='able(this.form.Finish);'>


The value of the name attribut should be in quotes.
The keyword "this" is already a reference to "Finish":

<select name="Finish" onchange="able(this)">

Aug 30 '05 #2
pk
Hmm, I wasn't very close at all. I'm still not getting it. My code
appears as follows now. There is still no observable behavior. :(

<SCRIPT type="text/javascript"> >

function able(dropdown)
{
var myindex = dropdown.selectedIndex
if(myindex == 1) {

document.getElementById("MMDiv").style.visibility= "visible";
document.mainform.BalStep.focus();
}
else
{
document.getElementById("MMDiv").style.visibility= 'hidden';
}

</SCRIPT>
<Form Name="myform">
<tr>
<td height="7" width="177">
<div align="right"><font color="#000000" face="Comic Sans MS">Boring
Type:</font></div>
</td>
<td height="7" width="397"><div align="left"><font color=#000000
face="Comic Sans MS">

<select name="Finish" onchange='able(this);'>
<option></option>
<option>Rough</option>
<option>Finish</option>
</select></font></div></td>

<DIV ID="MMDiv" style="visibility:hidden">
<LABEL FOR="BalStep">
<SELECT name=BalStepVal>
<option></option>
<option>Balanced Cutting</option>
<option>Step Cutting</option>
</SELECT>
</DIV>
</FORM>
</tr>

Aug 30 '05 #3
ASM
pk wrote:
Here is my code, and it's not working. Please help me get through
this. I've read every single tutorial and you may even see remnants of
some of their variables in my code. I don't know if I'm close, but I
feel that I'm getting there.

Thanks in advance for any help. I much appreciate it.

-pk

<SCRIPT>

function able(dropdown)
{
var myindex = dropdown.selectedIndex
if(myindex = 1) {
MMDiv.style.visibility='visible';
document.getElementById('MMDiv').style.visibility= 'visible';
mainform.BalStep.focus();
}
else {
MMDiv.style.visibility='hidden';
document.getElementById('MMDiv').style.visibility= '';
}

</SCRIPT>

<Form Name="myform">
<tr>
<td height="7" width="177">
<div align="right"><font color="#000000" face="Comic Sans MS">Boring
Type:</font></div>
</td>
<td height="7" width="397"><div align="left"><font color=#000000
face="Comic Sans MS">

<select name=Finish onchange='able(this.form.Finish);'>
<option></option>
<option>Rough</option>
<option>Finish</option>
</select></font></div></td>

<DIV ID="MMDiv" style="visibility:hidden">
<LABEL FOR="BalStep">
<SELECT name=BalStepVal>
<option></option>
<option>Balanced Cutting</option>
<option>Step Cutting</option>
</SELECT>
</DIV>
</FORM>
</tr>

--
Stephane Moriaux et son [moins] vieux Mac
Aug 31 '05 #4
ASM said the following on 8/30/2005 8:47 PM:
pk wrote:
Here is my code, and it's not working. Please help me get through
this. I've read every single tutorial and you may even see remnants of
some of their variables in my code. I don't know if I'm close, but I
feel that I'm getting there.

Thanks in advance for any help. I much appreciate it.

-pk

<SCRIPT>

function able(dropdown)
{
var myindex = dropdown.selectedIndex
if(myindex = 1) {


if (myIndex==1)

== is comparison
= is setting the variable.

Since it can set the var myindex to 1, it will always evaluate as true
so you never get to the else branch.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Aug 31 '05 #5
pk
OK, when I initially posted this, I didn't think I was all that close
to having it work. Now I swear it should be working, but it's not.
I'm posting some simplified code with comments of my thought process
(SCARY!). Tell me where I went wrong please. :) (These comments don't
truly exist in my code, I added them for insight. They're commented
Java-style since I don't write in HTML or JavaScript.)

Thanks for helping. I realize this is frustrating and you probably
just want to tell me to go read a JavaScript book.

<html>
<SCRIPT type="text/javascript"> >

function able(dropdown)

{
var myindex =
document.myform.dropdown.options[document.myform.dropdown.selectedIndex].value
// the line above put the value of my dropdown menu selection in the
variable myindex. this value will be 0, 1, or 2.
if(myindex == 1) {
document.getElementById('BalStepDiv').style.visibi lity="visible";
document.myform.BalStepVal.focus();
// in the case that myindex is equal to 1, i would like
to set the BalStepDiv <div> to visible.
}
else {
document.getElementById('BalStepDiv').style.visibi lity="hidden";
// in the case that myindex is not equal to 1, i would
like to set the BalStepDiv <div> to hidden.
}

</SCRIPT>

<body>
<Form Name="myform">
Test Select:
<select name="Finish" onchange='able(this);'>
<option></option> //selectedIndex == 0
<option>Rough</option> //selectedIndex == 1
<option>Finish</option> //selectedIndex == 2
</select>

<div id=BalStepDiv style="visibility:hidden;">
// the line above sets everything between the <div> </div> tags to
hidden, until that is changed by the function above.
<select name=BalStepVal>
<option></option>
<option>Balanced Cutting</option>
<option>Step Cutting</option>
</select>
</div>
</form>
</body>
</html>

Aug 31 '05 #6
pk
BINGO! I understand how this works now.
Instead of var myindex =
document.myform.dropdown.optio*ns[document.myform.dropdown.se*lectedIndex].value
;
i changed it to
var myindex = document.myform.Finish.selectedIndex;

I finally see how the naming convention works. Thanks for your help.

Aug 31 '05 #7
ASM
Randy Webb wrote:
ASM said the following on 8/30/2005 8:47 PM:
if(myindex = 1) {


if (myIndex==1)

== is comparison


yeap, I didn't fix it
but others did

--
Stephane Moriaux et son [moins] vieux Mac
Aug 31 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Rowland Hills | last post by:
I have a table which is returning inconsistent results when I query it! In query analyzer: If I do "SELECT * FROM TABLE_NAME" I get no rows returned. If I do "SELECT COL1, COL2 FROM...
1
by: David Lawson | last post by:
The line indicated below from my php script is very slow (about 10 seconds). I have this field indexed so I thought that it would be much faster. Could someone tell me what might be wrong? I'm also...
17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
9
by: Mike R | last post by:
Hi, I cant figure out how to do this.... for example: Select name from mytab order by col1 could return Mike
10
by: serge | last post by:
Using "SELECT * " is a bad practice even when using a VIEW instead of a table? I have some stored procedures that are identical with the difference of one statement in the WHERE clause. If I...
14
by: deko | last post by:
Can the DROP TABLE statement be used with a select or where statement? DROP TABLE SELECT * FROM tblTablesImported WHERE Import_ID Not In (SELECT FROM tblTablesInternal); Or do I have to...
3
by: Agnes | last post by:
My tables got over 10,000 records, As I drag & drop the adapter into my form, it's select command must show all the record. question1) Now,i only want to select the data in this current period...
33
by: Peter | last post by:
People are telling me it is bad to put select * from <atable> in a view. I better should list all fields of the table inside the definition of the view. I dont know exactly why but some...
2
by: fniles | last post by:
Is there a drag & drop even on tag SELECT, like maybe something like <SELECT ondragdrop={go to function drag & drop}>) ? Thank you
5
by: paragpdoke | last post by:
Hello Everyone. I'm new to XSL and couldn't get something to work. Sample XML excerpt: <root> <ObjectTemplate> <NodeType1></NodeType1> <NodeType2></NodeType2> </ObjectTemplate> <Object>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.