Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable Fields Then Enable Them Again on Select

Status
Not open for further replies.

scripter73

Programmer
Apr 18, 2001
421
US
Hi,

I have a form containing a select and three text fields that's defined as follows:


<form name="searchActForm">

.....

<select name="actdate" size="1" onchange="DisableDate();DisableName();">
<option selected value="" onchange="EnableDate();EnableName();">Please select</option>
<option value="TODAY">Today</option>
<option value="-1">Yesterday</option>
<option value="-2">Last 7 Days</option>
<option value="-30">Last 30 Days</option>
<option value="-60">Last 60 Days</option>
</select>

<input name="startDate" type="text" size="10" maxlength="10">

<input name="endDate" type="text" size="10" maxlength="10">

<input name="lastName" type="text" size="10" maxlength="30">






function DisableDate(){


document.searchActForm.startDate.value = "";
document.searchActForm.endDate.value = "";

document.searchActForm.startDate.disabled = true;
document.searchActForm.endDate.disabled = true;
}//DisableDate()

function DisableName(){

document.searchActForm.lastName.value = "";
document.searchActForm.lastName.disabled = true;

}//DisableName()

function EnableDate(){
document.searchActForm.startDate.disabled = false;
document.searchActForm.endDate.disabled = false;

document.searchActForm.startDate.value = "";
document.searchActForm.endDate.value = "";



}//EnableDate()

function EnableName(){
document.searchActForm.lastName.disabled = false;

document.searchActForm.lastName.value = "";

}//EnableName()




Now my Javascript functions are defined above. Here's what they do:

Disable Date();DisableName() - disables the startDate,endDate, and lastName fields if user clicks anything in the dropdown list

EnableDate();EnableName() - enables the startDate,endDate, and lastName fields if user clicks anything in the dropdown list

What's working is the disabling of the fields if the user selects anything other than the default from the drop-down list, but what's not working is the enabling of those same fields when the user selects "Please select" again.

Thanks in advance.

scripter73





Change Your Thinking, Change Your Life.
 

You cannot put an onchange event on an option. You'll have to move your logic to the onchange event of the select box.

Hope this helps,
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top