bigrich wrote:
<script type="text/javascript">
function GetOptVal(OptVa l)
var OptVal;
{
^
Fantasy syntax. It has to be
function /identifier/(/comma-separated list of named arguments/)
{
where the /.../ parts are to be replaced with meaningful code.
Local variables are created automatically for named arguments;
redeclaring them with a `var' statement is definitely harmful.
if(OptVal="XX") document.form1. chkbox1.disable d = false;
^[1] ^^^^^^^^^^^^^^^ ^^^^^^^[2]
[1] The `=' operator specifies an assignment always.
You are looking for `==' (type-converting equals)
or `===' (strict equals).
}
^
Nesting error. If you would have indented the blocks, being a sign
of good code style in any structured programming language, you would
have noticed.
else
{
document.form1. chkbox1.checked = false;
^^^^^^^^^^^^^^^ ^^^^^^^[2] document.form1. chkbox1.disable d = true;
^^^^^^^^^^^^^^^ ^^^^^^^[2]
[2] Avoid obtaining the reference to the same object repeatedly.
It is inefficient regarding runtime and maintenance.
}
</script>
<form name="form1">
<select name="Opt1"
onchange=GetOpt Val(document.fo rm1.Opt1
^ [1]^^^^^^^^^^^^^^^ ^^^^^[1]
[1] Attribute values that contain certain characters, such as "(",
must be delimited with in single (') or double (") quotes.
Therefore you should quote attribute values always.
[2] The element object that fired the event can be referred with
`this' in event handler attribute values.
[document.form1. Opt1.selectedIn dex].value)>
^ <option value=" ">Select One</option>
<option value="XX">XX</option>
<option value="YY">YY</option>
<option value="ZZ">ZZ</option>
</select>
<input type="checkbox" name="chkbox1" />
^
This is X(HT)ML syntax, however you write HTML (as can be inferred
from your `script' element's content). So omit the forward slash.
</form>
Probably you are looking for something like this:
<script type="text/javascript">
function enableDisable(o , sName, b)
{
var o = o.form.elements[sName];
if (o)
{
// the specified control will enabled and checked,
// or disabled and unchecked
o.disabled = !b;
o.checked = b;
}
}
</script>
<form action="" ...>
<select name="Opt1"
onchange=
"enableDisable( this, 'chkbox1', this[this.selectedIn dex].value == 'XX');">
<option value=" * *">Select One</option>
<option value="XX">XX</option>
<option value="YY">YY</option>
<option value="ZZ">ZZ</option>
</select>
<input type="checkbox" name="chkbox1">
</form>
Please adhere to the FAQ <URL:http://jibbering.com/faq/>,
especially <URL:http://jibbering.com/faq/#FAQ4_43>, next time.
PointedEars