473,322 Members | 1,522 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,322 software developers and data experts.

Listbox changes textbox to disabled and grey

How can I get a listbox to change a textbox on some selections.
I have a listbox which only needs to be filled in on some selections.

Is there a way I can have on some selections the textbox go
disabled and turn grey?

Aug 29 '06 #1
3 7239
Br**************@gmail.com wrote:
How can I get a listbox to change a textbox on some selections.
I have a listbox which only needs to be filled in on some selections.

Is there a way I can have on some selections the textbox go
disabled and turn grey?
You can disable it, but what it looks like when disabled is up to the
browser. You may be able to affect the appearance using CSS, but that
is inconsistent across browsers.

Here's a quick example:

<script type="text/javascript">
function modTextbox()
{
document.formA.textA.disabled = !!(document.formA.selA.value%2);
}
window.onload = modTextbox;
</script>
<form name="formA" action="">
<div>
<select id="selA" onchange="modTextbox();">
<option value="0">0
<option value="1">1
<option value="2">2
<option value="3">3
</select>
<br>
<label for="textA"><input type="text" id="textA">Enable
only if selection is an even number</label>
</div>
</form>
--
Rob

Aug 29 '06 #2
Thanks Rob
I still dont get it!!!
do you have an example where the first option is normal
but second option disables textbox?

RobG wrote:
Br**************@gmail.com wrote:
How can I get a listbox to change a textbox on some selections.
I have a listbox which only needs to be filled in on some selections.

Is there a way I can have on some selections the textbox go
disabled and turn grey?

You can disable it, but what it looks like when disabled is up to the
browser. You may be able to affect the appearance using CSS, but that
is inconsistent across browsers.

Here's a quick example:

<script type="text/javascript">
function modTextbox()
{
document.formA.textA.disabled = !!(document.formA.selA.value%2);
}
window.onload = modTextbox;
</script>
<form name="formA" action="">
<div>
<select id="selA" onchange="modTextbox();">
<option value="0">0
<option value="1">1
<option value="2">2
<option value="3">3
</select>
<br>
<label for="textA"><input type="text" id="textA">Enable
only if selection is an even number</label>
</div>
</form>
--
Rob
Aug 29 '06 #3
Br**************@gmail.com wrote:
Thanks Rob
I still dont get it!!!
do you have an example where the first option is normal
but second option disables textbox?
To disable an element that has a disabled attribute (button, input,
optgroup, option, select, textarea) set its value to true. To enable
it again, set disabled to false. The basic algorithm is:

if (condition) {
elementReference.disabled = true;
} else {
elementReference.disabled = false;
}

A shorthand method is to set the value of the disabled attribute to the
outcome of the condition statement:

elementReference.disabled = (condition);

That's effectively the same as the above 5 lines of code. The use of
"!!" in my earlier post was just to make sure that (condition) returned
true or false, it is probably not needed. Here's another example:

<form action="">
<div>
<select onchange="
if ( 1 == this.selectedIndex ) {
this.form.textA.disabled = true;
} else {
this.form.textA.disabled = false;
}
">
<option>Enable input
<option>Disable input
</select>
<input type="text" id="textA">
</div>
</form>

It's possible to get the two out of sync by reloading the page
(depending on the browser) as the input will probably become enabled
again but the selected option may not be reset. Hence my use of an
onload function to make sure they were synchronised.
--
Rob

Aug 29 '06 #4

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

Similar topics

4
by: | last post by:
Please, help. I created my contol, ButtonX, which subclasses System.Forms.Windows.Button class. I am doing my own paiting, by overriding OnPaint and OnPaintBackground (without calling base...
0
by: Jason Freeman | last post by:
Hi, (Cross-posted to microsoft.public.dotnet.framework.adonet) I've got a form with a listbox and a textbox on it. Both are bound to a DataView, which is sorted on the "Name" field of the...
3
by: Steve Le Monnier | last post by:
When you make a textbox control disabled ( txtText1.Enabled = false; ) You're left with grey text on a greyer background, which is not ideal. The Read-Only property is no use to me as I need to...
7
by: Grant Schenck | last post by:
Hello, I have a ListBox control on a form. I add members of a class to the Items collection. They show up and I can select them. The text shown is from my classes ToString override. Now,...
0
by: Alpha | last post by:
Hi, I have a listbox and a textbox which is bind to the same dataset's column. So the selected item is display in the textbox availbe for editing. When I change the text in the textbox it has...
1
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What...
5
by: acord | last post by:
Hi, Is there such thing that an item in the listbox is disabled and is appeared grey-out? How can I implement this in html/javascript? Thanks A
5
by: CCLeasing | last post by:
Hello, I have searched google but can not find a straight forward answer to my problem. Hopefuly someone will be kind enough to offer their expertise. Please forgive if this seems a bit convoluted...
17
by: govolsbaby | last post by:
Is there a way to leave the button forecolor unchanged when it is disabled? I have multiple buttons on the form and depending on various user inputs, some will or will not be enabled but I'd...
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...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.