How to control a Checkbox?

liunx

Guest
I have a checkbox in a form. In another part of the page, I need to control that checkbox in an If Then condition. Like, If checked Then do this else do that. Can I do it with html or have to use asp? What will be the code?<br />
<br />
Thanks!<br />
<br />
Sinan<!--content-->Welcome to the forums.<br />
<br />
JavaScript is easily capable of doing this. Could you perhaps explain how you want it to work in a bit more detail please?<!--content-->Thank you for your prompt response. Greetings to you and to anybody here in these forums.<br />
<br />
That form is running in an asp page. When submit button is pressed, an asp code checks it with the following code :<br />
<br />
<%<br />
If Request.Form("btnUpdate.x") <> 0 Then ...<br />
<br />
does some orher jobs. What I need is to add a checkbox into the form and control it when submit button is pressed if it was selected or not. If selected then do this else do that.<br />
<br />
Hope this is clear enough.<br />
<br />
Thanks.<!--content-->javascript, as fred pointed out, is the easiest solution, but if you are using asp, you could do it as well. Javascript would be implemented as such:<script type="text/javascript"><br />
<br />
function isChecked(box) {<br />
if(box.checked) {<br />
// checked<br />
}<br />
else {<br />
// not checked<br />
}<br />
return true; // submit form<br />
}<br />
<br />
</script><br />
<br />
<form onsubmit="return isChecked(this.myCheckBox)">or similar :)<!--content-->steelersfan88's javascript will work, but javascript should never be used solely in dynamic pages simpy because it is so easy to turn off (there are also differences in implementation between browsers, but this problem is less and less important these days). You will want to also include asp script in the page to handle the previous situation.<br />
<br />
If you are unsure as to how to deal with checkboxen in asp, check out this article (<!-- m --><a class="postlink" href="http://www.codehungry.com/asptut/checkboxes.asp">http://www.codehungry.com/asptut/checkboxes.asp</a><!-- m -->)<!--content-->and of course, since you are using asp now, it would be easiest on your part to stick to one language :)<!--content-->Thank you for all inputs. I did it like that :<br />
<br />
I set the checkbox Value to "1" and checked that condition with the following code :<br />
<br />
<% if Request.Form ("CheckBoxName") = "1" Then ...<br />
<br />
It worked fine like this. What I didn't know was that the Value set in the properties is the value that is assigned when box is ticked.<br />
<br />
You helped me much. Thank you!<br />
<br />
Sinan<!--content-->
 
Back
Top