Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show Submit ONLY if a checkbox is checked 2

Status
Not open for further replies.

MikeT

IS-IT--Management
Feb 1, 2001
376
US
On my page I have two check boxes in a form, and a Submit button. I want the Submit button to not appear or at least be greyed out if none of the checkboxes is checked. Is this possible with VBScript? Possibly JavaScript?

Thanks for your time!
 
Here ya go -- :) It also turns it back off if they uncheck it.

<html>
<head>
<title>test</title>
<script language=javascript>

function checkIt(){
if (document.thisForm.c1.checked == true || document.thisForm.c2.checked == true)
document.thisForm.submit.disabled = false;
else
document.thisForm.submit.disabled = true;
}

</script>
</head>
<body onLoad=&quot;document.thisForm.submit.disabled = true;&quot;>
<form name=thisForm action=&quot;somepage.asp&quot; method=post>
<input type=checkbox name=c1 onClick=&quot;checkIt();&quot;>
<input type=checkbox name=c2 onClick=&quot;checkIt();&quot;>
<input type=submit name=submit value=submit>
<input type=reset name=reset value=reset>
</form>
</body>
</html>

hope it helps!
Paul Prewett
 
One problem that I saw with code above is if you hit the reset button it clears the check boxes; however, it did not turn the 'submit' button back off. I add the resetIt() function to allow for this situation.


<html>
<head>
<title>test</title>
<script language=javascript>
function checkIt(){
if (document.thisForm.c1.checked == true || document.thisForm.c2.checked == true)
document.thisForm.submit.disabled = false;
else
document.thisForm.submit.disabled = true;
}

function restIt(){
document.thisForm.submit.disabled = true;
}

</script>
</head>
<body onLoad=&quot;document.thisForm.submit.disabled = true;&quot;>
<form name=thisForm action=&quot;somepage.asp&quot; method=post>
<input type=checkbox name=c1 onClick=&quot;checkIt();&quot;>
<input type=checkbox name=c2 onClick=&quot;checkIt();&quot;>
<input type=submit name=submit value=submit>
<input type=reset name=reset value=reset onClick=&quot;restIt()&quot;>
</form>
</body>
</html>


I hope this was helpful.

Wayne Sellars
 
Here is the VBScript Version of what you are looking for...
<HTML>
<HEAD>
<script language=vbscript>
function checkbox1_onclick()
If Test.checkbox1.checked = True then
Test.submitMe.style.display=&quot;&quot;
Else
Test.submitMe.style.display=&quot;none&quot;
End If
end function
</script>
</Head>
<BODY>
<form ID=Test>
<input type=CheckBox ID=CheckBox1>
<input type=Submit Style=&quot;Display: none;&quot; ID=&quot;SubmitMe&quot; Value=&quot;Submit&quot;>
</form>
</BODY>
</HTML>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top