Client-side enable/disable button

  • Thread starter Thread starter M O J O
  • Start date Start date
M

M O J O

Hi,

I have a webform with a textbox and a button.

When the textbox is empty (=""), I want the button to be disabled. When
the user enters text in the textbox, the button must be enabled.

Is this possible?

(please if possible, show me the code)

Thanks!!!

M O J O
 
You could do this by making your textbox AutoPostBack=true, and then
dropping some enable/disable code for your button into the event -- but that
would be horribly annoying (lots of postbacks).

A better alternative is probably to look at javascript solutions.
 
M said:
Hi,

I have a webform with a textbox and a button.

When the textbox is empty (=""), I want the button to be disabled.
When the user enters text in the textbox, the button must be enabled.

Is this possible?

(please if possible, show me the code)

Thanks!!!

M O J O

Something like:
<input type="text"
onChange="document.forms[0].myButton.disabled=(this.value='');" >
 
Hello Riki,

I think you mean (this.value == '');

Otherwise youre consistently setting the value to an empty string.

--
Matt Berther
http://www.mattberther.com
M said:
Hi,

I have a webform with a textbox and a button.

When the textbox is empty (=""), I want the button to be disabled.
When the user enters text in the textbox, the button must be enabled.

Is this possible?

(please if possible, show me the code)

Thanks!!!

M O J O
Something like:
<input type="text"
onChange="document.forms[0].myButton.disabled=(this.value='');" >
 
Hi,

If I use AutoPostBack, this wouldn't be client-side, right? :o) ... but
thanks anyway!

:o)

Regards
Mojo
 
Hi,

Cool thanks!!!

I just made a little correction...

Me.txtMyTextBox.Attributes.Add("OnKeyUp", "document.all." &
Me.cmdMyButtonTlfSøg.ClientID & ".disabled=(this.value=='')")

This works excatly like I wanted.

THANKS!!!!!!!

M O J O

M said:
Hi,

I have a webform with a textbox and a button.

When the textbox is empty (=""), I want the button to be disabled.
When the user enters text in the textbox, the button must be enabled.

Is this possible?

(please if possible, show me the code)

Thanks!!!

M O J O


Something like:
<input type="text"
onChange="document.forms[0].myButton.disabled=(this.value='');" >
 
Back
Top