PDA

View Full Version : Disable checkboxes based in other checkboxes.



gastongr
04-24-2006, 07:56 PM
Hello,
i'm new here :D
I need some help, i have a hosting directory and in the submission page the categories are selected using checkboexes.
A site can be submitted to many directories, but some users are abusing and submitting their sites for example to the windows hosting and to the linux hosting directories at the same time, which is ridiculous.

So i need to disable the checkbox of the windows category when the linux checkbox is checked and viceversa.
Same goes for the resellers, shared and dedicated categories, when one is selected the other should be disabled.

Can someone help me?

Thanks so much in advance.
Gaston

Twey
04-24-2006, 08:02 PM
Pointless. Check it server-side.

gastongr
04-24-2006, 08:15 PM
Well, i'm trying too but having both solutions will help me decide which to use.
Why you say it's pointless?

djr33
04-24-2006, 08:16 PM
The downside to that, though, is you'd have to decide.

If one clicked "windows", then "linux", it would switch to linux, meaning that's their first choice.

If it were server side, you'd have to say "if both, then choose windows" while linux might be their first choice.

then again, they're abusing the site, as you said, so not like you care that much about what they want ^_^

Server side is more secure, and probly easier, though.

Twey
04-24-2006, 08:18 PM
You cannot use Javascript alone for this. It can be bypassed with ease.
You have two options: to use server-side checking, or to use both server-side and client-side.
Besides, what if they do indeed offer both Windows and Linux hosting?

gastongr
04-24-2006, 08:25 PM
If one clicked "windows", then "linux", it would switch to linux, meaning that's their first choice.
i get your point, but what i need is to dissable the windows checkbox if the linux is selected, by dissable i mean it's not clickeable, it'll become clickeable only if the user unselects "linux"

then again, they're abusing the site, as you said, so not like you care that much about what they want ^_^
I care about what honest users want, a fair directory.
I don't care about what not honest users want which is to promote their websites spamming.

Twey,
thanks for your reply

Besides, what if they do indeed offer both Windows and Linux hosting?
I'm trying to disable this in a page to add hosting plans, registered hosting companies can add as many plans as they want, if the company offers hosting and linux plans they can add both of them.

Ickyb0d
04-24-2006, 08:27 PM
maybe i'm just missing something... but if you only want one or the other checked... why not just use radio buttons?

Twey
04-24-2006, 08:40 PM
Aha, very well. This makes sense.
Ickyb0d: If there are more than one set of buttons, this could be problematical.

<script type="text/javascript">
function checkDepends(element) {
for(var i=0;i<element.form.elements.length;i++)
if(element.form.elements[i].className.indexOf("depends-" + element.name) != -1)
element.form.elements[i].disabled = element.checked;
else if(element.form.elements[i].className.indexOf("conflicts-" + element.name) != -1)
element.form.elements[i].disabled = !element.checked;
}
</script>

<!-- This should allow you to create a form like this: -->

<form action="f.php" method="post">
<input type="checkbox" name="linux" class="conflicts-windows">
<input type="checkbox" name="ssh" class="depends-linux">
<input type="checkbox" name="cpanel" class="depends-linux">
<input type="checkbox" onclick="checkDepends(this);" name="windows" class="conflicts-linux">
<input type="checkbox" name="aspdotnet" class="depends-windows">
<input type="text" name="netbiosname" class="depends-windows">
</form>Untested, but should work. Remember that it isn't a secure solution, and must be used in tandem with a server-side check.

gastongr
04-24-2006, 08:50 PM
Thanks so much!, i'm going to try this right now

gastongr
04-24-2006, 08:55 PM
Well, it's not working very well, however i'll try to make it server side as you suggested.
Thanks so much again!

mwinter
04-24-2006, 11:18 PM
maybe i'm just missing something... but if you only want one or the other checked... why not just use radio buttons?If there are more than one set of buttons, this could be problematical.Care to explain that line of reasoning?



<fieldset>
<legend>Platform</legend>
<ul>
<li>
<label for="linux">
<input id="linux" name="platform" type="radio" value="linux" checked>
Linux
</label>
</li>
<li>
<label for="windows">
<input id="windows" name="platform" type="radio" value="windows">
Windows
</label>
</li>
</ul>
</fieldset>
<fieldset>
<legend>Server Disposition</legend>
<ul>
<li>
<label for="shared">
<input id="shared" name="server-disposition" type="radio" value="shared" checked>
Shared
</label>
</li>
<li>
<label for="dedicated">
<input id="dedicated" name="server-disposition" type="radio" value="dedicated">
Dedicated
</label>
</li>
<li>
<label for="reseller">
<input id="reseller" name="server-disposition" type="radio" value="reseller">
Reseller
</label>
</li>
</ul>
</fieldset>
I fail to see any problems with that (though the OP would undoubtely want to style it), and it facilitates precisely what the original post describes.



[...] i'll try to make it server side as you suggested.You really have no choice. Relying on client-side validation to do the all work is practically begging for someone to submit false or erroneous data to you. For example, simply having client-side scripting disabled means that the user is unencumbered from any constraint you would like to enforce. Not even a type of control (like radio buttons or select elements) can provide security in a situation like that.

Mike

djr33
04-24-2006, 11:42 PM
I'd totally go with radio buttons. It also wouldn't annoy people by "not letting them" click the other checkbox... they have to choose.

Surely that's easier than disabling checkboxes.

Maybe I'm missing something.