I want to disable the text box, based on the value selected from the list box



I want to disable the text field base on the value selected from the list box.

Please help me out

Thanks & Regards

If the value of the selected item in the list box == a certain value, set the disabled property of the textbox to true.

thanks for ur reply

please give the code for this

thanks & regards



I want to disable the text box based on the value selected from the list box

please help me out

Thanks & Regards.


Can you at least provide the code for the select list and the textbox? and then we can help you with the javascript.

Why are you duplicating your question in another thread?
This thread is the same as this one

this is my code

<select name=“vcat” id=“vcat” >Vehicle-Type
<option name=“vcat” value=“own”>Own
<option name=“vcat” value=“attached”>Attached
<input type=“text” name=“vcomm”>
<input type=“text” name=“vstatus”>

when i selected the ‘own’ from the list box then i want to disable the two text boxes

thanks & regards


That html has errors in it.

Why have you given names to the options? How will you be using those names?

Also, not all your option labels are enclosed properly within option tags.

You need to fix those errors first.

This will do it for you.

You need to have the first select box ( “select …”) so that the onchange handler fires when you move from it to the other two boxes.

<!doctype HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>


<meta http-equiv=“Content-Type” content=“text/html; charset=windows-1252”>
<title>Disable Text Boxes</title>
<script type=“text/javascript”>
function disableTextBox(obj)
{ var selected=document.myForm.mySelect.options[obj.selectedIndex].value;
// invalid selection
if(selected==“999”){ return; }
// ------------
// valid selection
{ document.myForm.vcomm.disabled=true;


<form name=“myForm”>
<p><select name=“mySelect” onchange=“disableTextBox(this)”>
<option value=“999”>Select …</option>
<option value=“own”>Own</option>
<option value=“attached”>Attached</option>
</select> <input type=“text” name=“vcomm” value=“12345”>
<input type=“text” name=“vstatus” value=“98765”> </p>



Answered in the php forum