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

Enabling/disabling a text filed from a select/option

Hi,
I need help!
I have a SELECT/OPTION list.
My goal is to have a TEXT input field in a form that is normally
disabled, but it should become enabled when the user select one
predefined OPTION. If the user change idea and select another OPTION,
the TEXT input field should be disabled again.
I hope I'm understandable.

Sorry for my bad English.

Thank You!

Jul 23 '05 #1
4 2568
Old Lady wrote:
Hi,
I need help!
I have a SELECT/OPTION list.
My goal is to have a TEXT input field in a form that is normally
disabled, but it should become enabled when the user select one
predefined OPTION. If the user change idea and select another OPTION, the TEXT input field should be disabled again.
I hope I'm understandable.

Sorry for my bad English.

Thank You!


English is fine, don't worry.

If you set a form field to disabled in your HTML, users with JavaScript
disabled will never be able to use it. It's better to disable it when
the page loads, using JS.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled</title>
<script type="text/javascript">

window.onload = function()
{
var s, t;
if ((s = document.getElementById('foo'))
&& (t = document.getElementById('bar'))
&& ('undefined' != typeof t.disabled))
{
t.disabled = true;
s.onchange = function()
{
var bWhich = (this.selectedIndex == 4)
t.disabled = !bWhich;
if (bWhich)
{
t.focus();
t.select();
}
}
}
s.onchange();
}

</script>
</head>
<body>
<form>
<select id="foo" name="foo" size="5">
<option value="alpha">alpha</option>
<option value="beta">beta</option>
<option value="gamma">gamma</option>
<option value="delta">delta</option>
<option value="epsilon">other</option>
</select>
<input id="bar" type="text" name="bar" value="test" />
</form>
</body>
</html>

Just set ---> this.selectedIndex == 4
to the index of the enable/disable option (JS counts from 0). You're
using the window's onload handler (same as <body onload="...">) so
you'll need to 'bundle' this with any other onload routines you're
calling.

Jul 23 '05 #2
On Wed, 09 Feb 2005 09:52:10 GMT, Old Lady wrote:
Hi,
I need help!
I have a SELECT/OPTION list.
My goal is to have a TEXT input field in a form that is normally
disabled, but it should become enabled when the user select one
predefined OPTION. If the user change idea and select another OPTION,
the TEXT input field should be disabled again.
I hope I'm understandable.

Sorry for my bad English.

Thank You!


To aplogize for english that is better than many of for whom it's the
native tongue is .... Well, your English is quite acceptable!
Jul 23 '05 #3
JRS: In article <1r***************************@40tude.net>, dated Thu,
10 Feb 2005 00:12:41, seen in news:comp.lang.javascript, al jones
<al**********@shotmail.com> posted :
On Wed, 09 Feb 2005 09:52:10 GMT, Old Lady wrote:
Sorry for my bad English.

Thank You!


To aplogize for english that is better than many of for whom it's the
native tongue is .... Well, your English is quite acceptable!


I agree with your conclusion, but consider you to be a manifestly
unqualified judge.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4
>If you set a form field to disabled in your HTML, users with JavaScript
disabled will never be able to use it. It's better to disable it when
the page loads, using JS.


I tried it and it works! :-)
Thank you very much for your help and sorry for this delay in
answering you, but I was out of city for a while... :-P
Jul 23 '05 #5

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

Similar topics

4
by: Fluffy Convict | last post by:
I have found a workaround to disable certain options in an option list: var p = document.forms.elements; p.selectedIndex=-1; This works perfectly in IE - the selectedIndex becomes unclickable....
5
by: Cillies | last post by:
Hi All, This message is a continuation of an earlier post, so please accept my apologies as I believe I would get a better response this way. Problem: I have 4 combo boxes which I want to...
2
by: Marcus | last post by:
Is it possible to enable/disable one Option Group from another group. For example, when I open my form I want OptionGroup1 disabled, and OptionGroup2 enabled. Private Sub Form_Open(Cancel As...
2
by: HumptyDumpty | last post by:
Does anyone know if there is a problem with re-enabling the Screen Saver after it has been disabled programmatically. I am using the SystemParametersInfo function within User32.dll, and have...
1
by: Mark Noten | last post by:
This following HTML page works fine in Firefox 1.5 but not in IE6. Help is appreciated. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta...
2
by: mitzie | last post by:
Is it possible to enable and disable check box of active record using a continuous form? The problem with what I have done is if user entered multiple records, then clicked 1st option box, all...
1
anukagni
by: anukagni | last post by:
HI friends, In my access database i want to get in an operation which should reflect in the report as what i said... Concept -- this is an billing database. In the bill entry...
8
by: Richard Maher | last post by:
Hi, I am in a mouseup event for button A and I'd like to disable=false button B before starting some work. Is there anyway that an event for button B can then fire before my event processing for...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

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.