enable - disable <select>.

B

Bob Bedford

I've this code:

function checkdate(FormSubmit){
alert(document.getElementById('Mois').value);
if(eval(document.getElementById('Mois'))>0 &&
eval(document.getElementById('Annee'))>0){
document.forms['FormSubmit'].getElementByID('SELECTCONSTRUCTOR').disabled
= false; //can't reach the control here
}
else
{
document.forms['FormSubmit'].getElementByID('SELECTCONSTRUCTOR').disabled
= true; //can't reach the control here
}
}
....

<form name="FormSubmit" method="post" action="">
....
<select name="Mois" onChange=checkdate(this.form);>
....
<select name="Annee" onChange=checkdate(this.form);>
....
<select name="SELECTCONSTRUCTOR" disabled>

Now, what I would like, is to enable the SELECTCONSTRUCTOR if month and year
are selected (I mean different to 0).

I can't enable or disable. In fact I can't reach the control in the
checkdate function...

How can I enable/disable SELECTCONSTRUCTOR when my 2 fields are selected ???

BoB
 
M

Martin Honnen

Bob said:
I've this code:

function checkdate(FormSubmit){
alert(document.getElementById('Mois').value);
if(eval(document.getElementById('Mois'))>0 &&
eval(document.getElementById('Annee'))>0){
document.forms['FormSubmit'].getElementByID('SELECTCONSTRUCTOR').disabled
= false; //can't reach the control here
}
else
{
document.forms['FormSubmit'].getElementByID('SELECTCONSTRUCTOR').disabled
= true; //can't reach the control here
}
}
...

<form name="FormSubmit" method="post" action="">
...
<select name="Mois" onChange=checkdate(this.form);>
...
<select name="Annee" onChange=checkdate(this.form);>
...
<select name="SELECTCONSTRUCTOR" disabled>

Now, what I would like, is to enable the SELECTCONSTRUCTOR if month and year
are selected (I mean different to 0).

I can't enable or disable. In fact I can't reach the control in the
checkdate function...

How can I enable/disable SELECTCONSTRUCTOR when my 2 fields are selected ???

Forget about eval, you don't need it.
If you have two select elements in a form container then simply pass the
form to your function as you do e.g.
<select onchange="checkdate(this.form);"
and then in
function checkdate (formObject) {
var select1 = form.elements.Mois;
var select2 = form.elements.SELECTCONSTRUCTOR;
...
if (...) {
select2.disabled = false;
}
}
 
M

Michael Winter

Bob Bedford wrote on 18 Dec 2003 at Thu, 18 Dec 2003 15:41:46 GMT:
alert(document.getElementById('Mois').value);
if(eval(document.getElementById('Mois'))>0 &&
eval(document.getElementById('Annee'))>0){
document.forms['FormSubmit'].getElementByID('SELECTCONSTRUCTOR'
document.forms['FormSubmit'].getElementByID('SELECTCONSTRUCTOR'

In addition to what Mr Honnen and Mr Hikks said, you would have
trouble with the lines of code above.

1) The latter two lines have the method name in incorrect case; the
'D' in 'ID' should be lowercase.
2) All of those lines have names as arguments. Names are *not* the
same as IDs, and any browser that returns the correct element is
broken (namely, IE but possibly others). The retrieval of named
elements is accomplished using document.getElementsByName(). Be
aware that this returns a collection returning all elements that
match that name.

As Mr Hikks said, the better way of accessing named form controls
within a form element is through the use of the elements collection:

document.forms['form name'].elements['element name']

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top