Need to enable an ASP.NET button using JavaScript

I can successfully change the image displayed on a buton with this JavaScript code:

                       var button = document.getElementById("findReservationBtn");
                        button.src="images/btn_forward_flow.gif";

But I also need to disable and enable it, and am having trouble.

Can anybody help do it?

thanks,
newbieweb
newbiewebSr. Software EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

techExtremeCommented:
Hello,
Going with your existing code, assuming you have the imagebutton's reference in the button variable (i.e. it is not null first of all),
do this:
button.disabled = 'true';  \\for disabling the button
button.enabled = 'true'; \\ for enabling the button
Hope it helped,
Happy Coding!
0
techExtremeCommented:
err I guess a type, both ways you should use the disabled property only.
0
newbiewebSr. Software EngineerAuthor Commented:
I tried

button.disabled='false' and
button.disabled='true'

and for some reason I can disable the button but can not enable it this way:

button.disabled='false'

Anny ideas?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

techExtremeCommented:
Hi,
I guess you are trying to enable the same button which you disabled by clicking on itself.
Say you have a button1, you disable it by setting its disabled property to true. Now when you cannot click it again and execute its code as it is already disabled. You must have another method of enabling the button you just disabled,

say from another button click or any other event  you set the disabled button's property to false and it will be enabled.
For understanding purposes
I have two buttons: button1 and button2
on button1's click , i disable it by button1.disabled = 'true';
Now ,
to enable buton1, i use button2's click event by firing below code there
button1.disabled = 'false';
Did this help? Let me know.
Thanks.
0
newbiewebSr. Software EngineerAuthor Commented:
I am not trying to enable or disbable it from the button itself.  I am intercepting keystrokes.  So I know that the button is not getting re-enabled even though the JavaScript is being called.  I can see the image file changing properly and you can see in the code below hte proximity to the code which changes the image and enables and disable the button.

Do you see what I mean?

newbieweb

function CheckSize()
    {
        var elem = document.getElementById("recordLocatorTextBox");
       
        if (elem != null)
        {
            if (!isAlphaNumeric(elem.value))
            {
                alert("The confirmation number consists only of alphanumeric characters.  Please try again.");
            }
            else
            {
               var button = document.getElementById("findReservationBtn");
               number_of_characters = parseInt(elem.value.length);
               if(number_of_characters == 6)
                {
                        //display enabled button image
                        if ( button != null )
                        {
                            button.src="images/btn_forward_flow.gif";
                            button.disabled = 'false';
                        }
                        return true;
                }
                else
                {
                    if (number_of_characters>6)
                    {
                        alert("The confirmation number is only 6 characters long.  Please try again.");
                    }

                    // display disable button image
                    if ( button != null )
                    {
                        button.src="images/btn_forward_flow_dis.gif";
                        button.disabled = 'true';
                    }            

                    return false;
                }
            }
        }
   
0
techExtremeCommented:

Hello,
It works, just remove the quotes from 'true' and 'false'
i.e. use button.disabled = true; and button.disabled = false; and it will work perfectly.
As an example, I'm posting a html test form that i used just now ,
if removing quotes does not work for you, copy and paste below code in notepad and save as test.html and
check by clicking both buttons and effect of it in image.It works here.

<html>
<body>
<form id="form1" action="http://www.google.com" method="GET">
<input type="image" id="img1" type="image" src="http://www.bannermakerpro.com/images/sample6-greenpill.gif">
<a href="#" onclick="javascript: e()">enable</a>
<br />&nbsp;
<br />
<a href="#" onclick="javascript: d()">disable</a>
</form>
<br />
</body>
</html>

<script type="text/javascript">
function e()
{
 document.getElementById('img1').disabled=false;
 alert('enabled');
}
function d()
{
 document.getElementById('img1').disabled=true;
 alert('disabled');
}
</script>
Thanks,
Enjoy Coding
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.