Page 1 of 1

Enable a button in javascript

Posted: Thu Mar 03, 2011 11:30 pm
by Gopesh
I have a form with a checkbox and two buttons named submitt and continue.i want to disable the submitt button and enable the continue button at the same time when one clicks the checkbox. My form is:

<form name="apply">
<input type="checkbox" onClick="document.apply['submitt'].disabled =(document.apply['submitt'].disabled)? false : true" >
<input type="submit" id="submit" name="submitt" value="Submit Application" class="button" disabled>
<input type="button" name="continue" value="continue" id="continue" disabled/>
</form>

pls help ????

Re: Enable a button in javascript

Posted: Fri Mar 04, 2011 1:20 am
by Christopher
It should be disabled="disabled" (http://www.w3schools.com/tags/att_input_disabled.asp)

Call a function in your onclick. Something like this:

Code: Select all

<script type="text/javascript">
function submit_disable_toggle(){
    if (document.all || document.getElementByid){
        document.apply.submitt.disabled = !document.apply.submitt.disabled;
    }
}
</script>

Re: Enable a button in javascript

Posted: Fri Mar 04, 2011 1:43 am
by Gopesh
Thanks Christopher..it worked nice when calling a function on onclick. Final code is:
<html>
<head>
<script type="text/javascript">
function submit_disable_toggle()
{

document.apply['submitt'].disabled =(document.apply['submitt'].disabled)? false : true;
document.apply['continue'].disabled =(document.apply['submitt'].disabled)? false : true;

}
</script>
</head>

<body>
<form name="apply">
<input type="checkbox" id="check" onClick="submit_disable_toggle()">
<input type="submit" id="submit" name="submitt" value="Submit Application" class="button" >
<input type="button" name="continue" value="continue" id="continue" disabled="disabled"/>
</form>
</body>
</html>