Client-side enable/disable button

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
 
M

MWells

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.
 
R

Riki

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='');" >
 
M

Matt Berther

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='');" >
 
M

M O J O

Hi,

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

:eek:)

Regards
Mojo
 
M

M O J O

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='');" >
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top