Jump to content

[JavaScript] Checkbox to show Submit Button


Recommended Posts

<html><head><title>Korean Language School</title><script type="text/javascript">	function apply() {		document.frm.sub.disabled = true;		if (document.frm.chk.checked == true) {			document.frm.sub.disabled = false;		}		if (document.frm.chk.checked == false) {			document.frm.sub.enabled = false;		}			}</script></head><body><form id="apply" action="" name="frm">						<fieldset>							<legend>Customer Information</legend>								<dl>									<dt><label for="name">Name</label></dt>									<dd><input type="text" placeholder="First & Last Name" required="required" id="name"/></dd>								</dl>								<dl>									<dt><label for="email">Email</label></dt>									<dd><input type="email" placeholder="asklc@hotmail.com" required="required" id="email"/></dd>								</dl>								<dl>									<dt><label for="gender">Gender</label></dt>									<dd><input type="radio" name="gender"/>Male <input type="radio" name="gender"/> Female</dd>								</dl>								<dl>									<dt><label for="contact">Contact Details</label></dt>									<dd><input type="text" value="+65" required="required" id="contact"/></dd>								</dl>								<dl>									<dt><label for="Ask">Have you learnt Korean Before?</label></dt>									<dd><input type="radio" name="Ask" />Yes <input type="radio" name="Ask" />No</dd>								</dl>						</fieldset>						<fieldset>							<legend>Class Information</legend>								<dl>									<dt><label for="Course">Which Course Are you taking?</label></dt>									<dd><input type="radio" name="course" />Basic Course<br /><input type="radio" name="course" />Intermediate Course<br /><input type="radio" name="course" />Advanced Course</dd>								</dl>								<dl>									<dt><label for="frequency">How often will you like the class to be?</label></dt>									<dd><input type="radio" name="freq" />Twice a week<br /><input type="radio" name="freq" />Once a Week<br /><input type="radio" name="freq" />Once Every 2 Weeks</dd>								</dl>								<dl>									<dt><label for="time">What days do you prefer your lesson to be?</label></dt>									<dd><input type="checkbox" name="time" />Weekday<br /><input type="checkbox" name="time" />Saturday<br /><input type="checkbox" name="time" />Sunday</dd>								</dl>								<dl>									<dt></dt>									<dd style="padding-left: 100px;">I have agree to the <a href="#">Terms & Condition</a> <input type="checkbox" name="chk" onClick="apply()"></dd>								</dl>								<dl>									<dt></dt>									<dd><input type="button" name="sub" value="  Submit  " disabled="disabled" onclick="submit()"><input type="reset" value="  Reset  "/></dd>								</dl>						</fieldset>					</form>

I got my Javascript from a site [sorry, i've forgotten where] When i click on my " I have agree to the Terms & Condition " checkbox, my submit button becomes clickable again. However, when i tried this,

<script type="text/javascript">	function apply() {		document.frm.sub.disabled = true;		if (document.frm.chk.checked == true && document.frm.course.checked== true && document.frm.freq.checked == true && document.frm.time.checked == true) {			document.frm.sub.disabled = false;		}		if (document.frm.chk.checked == false && document.frm.course.checked == false && document.frm.freq.checked == false && document.frm.time.checked == false) {			document.frm.sub.enabled = false;		}			}</script>

No matter what i have checked, the submit button stays "Disabled" all the time.

Edited by jiyeonnie
Link to comment
Share on other sites

For the apply() function, the following should be able to work for you:

 function apply() {       if(document.frm.chk.checked == true)      {           document.frm.sub.disabled = false;      }     else // if the user unchecks the checkbox after checking it, then disable the submit again     {          document.frm.sub.disabled = true;      }  }

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...