473,403 Members | 2,270 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,403 software developers and data experts.

enable - disable <select>.

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
Jul 20 '05 #1
3 9183


Bob Bedford wrote:
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;
}
}

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
In article <3f*********************@news.sunrise.ch>, "Bob Bedford"
<be******@YouKnowWhatToDohotmail.com> writes:
I've this code:
http://www.jibbering.com/faq/#FAQ4_13

Will explain how to get a reference to a select list.
function checkdate(FormSubmit){
alert(document.getElementById('Mois').value);
if(eval(document.getElementById('Mois'))>0 &&
eval(document.getElementById('Annee'))>0){


http://www.jibbering.com/faq/#FAQ4_40

eval is not needed there, nor is the getElementById the most
efficient/cross-browser way to do that:

el1=document.forms['FormSubmit'].elements['Mois'];
value= +el1.options[el1.selectedIndex].value;
el2=document.forms['FormSubmit'].elements['Annee'];
value= +el2.options[el2.selectedIndex].value;

The + in the two lines converts the string value to a number.

if ( el1>0 && el2>0){
document.forms['FormSubmit'].elements['SELECTCONSTRUCTOR'].disabled=false;
}
else{
document.forms['FormSubmit'].elements['SELECTCONSTRUCTOR'].disabled=true;
}
--
Randy
Jul 20 '05 #3
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' <snip> 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

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk")
Jul 20 '05 #4

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

Similar topics

2
by: Andrea | last post by:
Hi, I'm trying to emulate part of our client-server application as a web site so customers can use it, and I'm stuck when it comes to re-ordering items in a list. Basically we have a list of...
1
by: Ang Talunin | last post by:
Hey, I wondering if it's possible to retrieve all the <option>-fields from a <select> when posting a <form> to a php file Example: I've got a form like this: <form action = phpfile.php...
6
by: Bonge Boo! | last post by:
This has got to be obvious, but I can't make it work. I have a form called with 3 pull down menus. They are linked to a database which generates the values for the <SELECT? Pull-downs. Lets...
4
by: joiv | last post by:
I'm making a <select></select> with lots of <option></option>. It contains all possible options. Because of the length of the list, I also have an <input type="text">. This is what I wish to do:...
5
by: Brian Foley | last post by:
Hello, I am used to using the label tag with check boxes and radio buttons in html forms. This allows me to click on the text of the label to activate/deactivate the check box / button, rather...
6
by: Chris Fink | last post by:
Does anyone know it is possible to include a small image(.gif .jpeg) within a <SELECT><option> so that the user would see the option text as well as a little image(icon) in the option? I know this...
6
by: joseph.lindley | last post by:
Forgive me for I am a bit of a web-dev novice - but I'm not doing too bad. I'm currently working with a bit of javascript to dynamically add <option>s into a select box. My code currently works...
4
by: Man-wai Chang | last post by:
-- iTech Consulting Co., Ltd. Expert of ePOS solutions Website: http://www.itech.com.hk (IE only) Tel: (852)2325 3883 Fax: (852)2325 8288
14
mikek12004
by: mikek12004 | last post by:
In a form I have 5 elements (e.g. pictures) and I wish for the user to be able to set the order of appearance. For this I have for each picture a select box (names select1 to select5) with "please...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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.