Forum Moderators: open

Message Too Old, No Replies

Enabling a Submit Button with Arguments

         

chief stains

9:10 am on Apr 3, 2006 (gmt 0)

10+ Year Member



Hi,

I want to disable and enable buttons on various parts of a web site. I have a function which takes two arguments, the form id/name and the button id/name, and attempts to enable/disable the button based on these arguments.

I cannot seem to get this to work when i pass arguments to the function, however it will work if i specify the form and button name within the function.

I have tried both the following ways and neither work

function submitEnable(formID, buttonID){ 
document.getElementById(formID).getElementById(buttonID).disabled=false;
}

and...

function submitEnable(formName, buttonName){
document.[formName].[buttonName].disabled=false;
}

Does anybody have any suggestions..?

Thanks

kaled

10:39 am on Apr 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are specifying an ID, it must be unique on the page, therefore there is no need to use a <form> to locate it.

getElementById() is a method of the document object.

Try this...

function enableButton(ID,enable){ // enable must be true or false
var b = document.getElementById(ID);
if (b) b.disabled =!enable;
}

Kaled.

chief stains

11:20 am on Apr 3, 2006 (gmt 0)

10+ Year Member



nice one, it works...

Thanks