Trying and failing to disable button in javascript

T

teddysnips

I'm trying to disable a button in javascript. At some point I want to
do it when a check box is checked, but for testing purposes I'm doing
it on the form submit.

var frm = document.getElementById('Form1');
frm.oldOnSubmit = frm.onsubmit;
frm.onsubmit = function() {fubar(); if (this.oldOnSubmit)
this.oldOnSubmit(); };

// Get document element
function getE(id) {
return document.getElementById(id);
}

function fubar() {
debugger;
var cmd = getE('cmdFilter');
cmd.style.visibility = "hidden";
cmd.disabled ='true';
window.status = "Please wait...";
document.title = window.status;
document.all.item("Form1").style.cursor = "wait";
return;
}

I'm hitting the debugger; breakpoint, but when the code has run the
button "cmdFilter" is unaffected - neither hidden nor disabled.

Help, please!

Thanks

Edward
 
P

Peter Bromberg [C# MVP]

check if your getE function is returning an object. Most likely it isn't.
ASP.NET has a NamingContainer hierarchy that mangles the ClientID of controls
to reflect their parent controls. That means that to get the correct
client-side control Id, you would need to do something like:

var cmd = getE( '<%=cmdFilter.ClientId %>' );

-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short Urls & more: http://ittyurl.net
 
T

teddysnips

check if your getE function is returning an object. Most likely it isn't.
ASP.NET has a NamingContainer hierarchy that mangles the ClientID of controls
to reflect their parent controls.  That means that to get the correct
client-side control Id, you would need to do something like:

var cmd = getE( '<%=cmdFilter.ClientId %>'   );

-- Peter
Site:http://www.eggheadcafe.com
UnBlog:http://petesbloggerama.blogspot.com
Short Urls & more:http://ittyurl.net

Thanks, Peter, but that doesn't work. In any case, getE function was
returning an object. What's peculiar is that if I set a watch on the
values of cmd.style.visibility and cmd.disabled their respective
values are "hidden" and 'true', as expected. However, this is not
reflected on the form, where the control remains stubbornly visible
and enabled.

Edward
 
M

Microsoft Newsserver

Why not add an onclick event to the button which hides it before passing the
event on for submit.

myonclick()
{
//your stuff

return true;
}


check if your getE function is returning an object. Most likely it isn't.
ASP.NET has a NamingContainer hierarchy that mangles the ClientID of
controls
to reflect their parent controls. That means that to get the correct
client-side control Id, you would need to do something like:

var cmd = getE( '<%=cmdFilter.ClientId %>' );

-- Peter
Site:http://www.eggheadcafe.com
UnBlog:http://petesbloggerama.blogspot.com
Short Urls & more:http://ittyurl.net

Thanks, Peter, but that doesn't work. In any case, getE function was
returning an object. What's peculiar is that if I set a watch on the
values of cmd.style.visibility and cmd.disabled their respective
values are "hidden" and 'true', as expected. However, this is not
reflected on the form, where the control remains stubbornly visible
and enabled.

Edward
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top