Simple JavaScript question

K

Kevin S. Goff

Hi....I realize this is a really basic question....

I have a webform (in VS.NET 2005). It has (among other things) a
combobox and a command button. At the beginning, the command button
is disabled....on the selectedindexchanged event of the combobox, I
want to enable the command button

Only way I know to do it is in the code-behind .CS file with a
postback, but I'd rather do it with Javascript....except I really
don't know the syntax very well.

Assuming my two controls were cboItem and btnSave, what would the
syntax be (in the HTML) to enable btnSave when cboItem changes?

Thanks a lot in advance,
Kevin
 
B

barry

The way I would do it so as not to get the post back would be to make the
dropdown a html control then
the javascript would look like this

document.body.all.item("btnSave").disabled = false;
 
L

Laurent Bugnion

Hi,
The way I would do it so as not to get the post back would be to make the
dropdown a html control then
the javascript would look like this

document.body.all.item("btnSave").disabled = false;

Why not rather use the standard way to do this? The "all" property
exists only in IE and is a fossile from the past.

The DOM Level 2 way is:

<select onchange="document.getElementById('btnSave').disabled=false;">
....

Also, the combo doesn't have to be a HTML control. You can use an
ASP.NET listbox, with AutPostback = false, and use SetAttribute to set
the javascript code.

HTH,
Laurent
 

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