faqts : Computers : Programming : Languages : JavaScript : Forms

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

37 of 67 people (55%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

How can I enable\disable a textbox? For example: select Hi! enable and selecting Bye! disable?

May 12th, 2004 01:59
Suban Asif, Erik Heidstra,


I saw its answer sometimes ago in Javascript knowledgebase, by 
someone. I can't remember the URL though. Anyway, I will reproduce it 
for you, thanks to its original author:
<SCRIPT language="JavaScript">
function skip () { 
 this.blur(); 
}
function disableTextField (field) {
  if (document.all || document.getElementById) 
    field.disabled = true;
  else {
    field.oldOnFocus = field.onfocus;
    field.onfocus = skip;
  }
}
function enableTextField (field) {
  if (document.all || document.getElementById)
    field.disabled = false;
  else {
    field.onfocus = field.oldOnFocus;
  }
}
</SCRIPT>
<FORM name="aForm">
 <INPUT type="text" name="aField" value="Kibology">
 <A href="javascript:enableTextField(document.aForm.aField)">Select Hi!
</A>
| <A href="javascript:disableTextField(document.aForm.aField)">Bye!</A>
</BODY>
</HTML>
Suban Asif