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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enable / Disable Field

Status
Not open for further replies.

Brianfree

Programmer
Feb 6, 2008
220
GB
Hi, i have a text field which a user has two type a number plate into. Please can someone show me how to make a button enabled if something is typed in & disable it again if they delete what they typed in?

Many thanks,

Brian
 
Hi

If we take your word "typed" strictly, then this :
Code:
<input type="text" value="" onkeyup="this.form.whatever.disabled=this.value==''">
<input type="button" name="whatever" disabled="disabled">
Note that the [tt]onkeyup[/tt] event will not be triggered if someone fills the [tt]input[/tt] by pasting the text with mouse. So usually the [tt]onchange[/tt] event is used in such case. The price is that the event happens only when the [tt]input[/tt] looses the focus.

But also note that neither the [tt]onchange[/tt] event will be triggered if the [tt]input[/tt] is filled programmatically, for example by the browser's [tt]form[/tt] completing functionality.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top