Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
156
rated 0 times [  160] [ 4]  / answers: 1 / hits: 60503  / 12 Years ago, thu, april 5, 2012, 12:00:00

How to enable the submit button in my HTML form and disable if checkbox was unchecked?



What is wrong with this code?



EnableSubmit = function(val)
{
var sbmt = document.getElementById(Accept);

if (val.checked == true)
{
sbmt.disabled = false;
}
else
{
sbmt.disabled = true;
}
}


The check box



<td width=30%>Do you accept Terms of Service agreement?</td>
<td width=10px style=min-width: 10px></td>
<td width=70%>
<input type=checkbox name=TOS value=Accept onClick=EnableSubmit> I agree to Terms of Service agreement.
</td>

More From » html

 Answers
1

Change your HTML to this:



<td width=30%>Do you accept Terms of Service agreement?</td>
<td width=10px style=min-width: 10px></td>
<td width=70%>
<input type=checkbox name=TOS value=Accept onClick=EnableSubmit(this)> I agree to Terms of Service agreement.
</td>


Reason it's not working: you're not passing your function anything. Actually, because you've not used parentheses with the function name, you've not called the function at all. Passing it this in the context of the onclick HTML event attribute means you're passing a reference to the element's DOM object, giving you access to its checked property.


[#86412] Tuesday, April 3, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hasanjustusf

Total Points: 76
Total Questions: 116
Total Answers: 100

Location: Virgin Islands (U.S.)
Member since Tue, Jul 7, 2020
4 Years ago
hasanjustusf questions
;