Jump to content

Checkbox (enable e disable)


J4m3s007
 Share

Recommended Posts

<html>
<head>
<title>(Type a title for your page here)</title>
<script language="JavaScript">
<!--

function enable_text(status)
{
status=!status;
document.f1.other_text.disabled = status;
}
//-->
</script>
</head>
<body>

<form name="f1" method="post"/>
    <!-- RAPIDSHARE -->
    <input name="RS" type="checkbox" id="rapidshare" onclick="enable_text(this.checked)" style="vertical-align:middle"/>
    <img src="hosts/RS_icon.png" style="vertical-align:middle"/>
    <!-- MEGAUPLOAD -->
    <input name="MU" type="checkbox" id="megaupload" onclick="enable_text(this.checked)" style="vertical-align:middle"/>
    <img src="hosts/MU_icon.png" style="vertical-align:middle"/>
    <!-- HOTFILE -->
    <input name="HF" type="checkbox" id="hotfile" onclick="enable_text(this.checked)" style="vertical-align:middle"/>
    <img src="hosts/Hotfile_icon.png" style="vertical-align:middle"/></br>
   <textarea name="other_text" cols="50" rows="10" id="download" disabled="disabled"></textarea>
</form>

</body>
</html>

O que está aqui a acontecer é que seleciono uma checkbox e fica enable depois seleciono a segundo continua bem, quando vou para desselecciono a segunda fica disable a textbox e não queria que isso acontecesse. Só queria que ficasse disable quando nenhuma checkbox tivesse um visto (enable).

Obrigado  😕

Link to comment
Share on other sites

Podes fazer assim

<html>
<head>
<title>(Type a title for your page here)</title>
<script language="JavaScript">
<!--

function enable_text(){
rs = document.getElementById('rapidshare');
mu = document.getElementById('megaupload');
hf = document.getElementById('hotfile');

if(rs.checked || mu.checked || hf.checked){
	document.f1.other_text.disabled = false;
}else{
	document.f1.other_text.disabled = true;
}
}
//-->
</script>
</head>
<body>

<form name="f1" method="post"/>
    <!-- RAPIDSHARE -->
    <input name="RS" type="checkbox" id="rapidshare" onclick="enable_text()" style="vertical-align:middle"/>
    <img src="hosts/RS_icon.png" style="vertical-align:middle"/>
    <!-- MEGAUPLOAD -->
    <input name="MU" type="checkbox" id="megaupload" onclick="enable_text()" style="vertical-align:middle"/>
    <img src="hosts/MU_icon.png" style="vertical-align:middle"/>
    <!-- HOTFILE -->
    <input name="HF" type="checkbox" id="hotfile" onclick="enable_text()" style="vertical-align:middle"/>
    <img src="hosts/Hotfile_icon.png" style="vertical-align:middle"/></br>
   <textarea name="other_text" cols="50" rows="10" id="download" disabled="disabled"></textarea>
</form>

</body>
</html>

Ou assim o caso de queres adicionar mais checkbox's.

<html>
<head>
<title>(Type a title for your page here)</title>
<script language="JavaScript">
<!--
function enable_text(){
var sites = ["rapidshare","megaupload","hotfile"];

for ( var i in sites ){
	if(document.getElementById(sites[i]).checked){
		document.f1.other_text.disabled = false;
		return
	}
}
document.f1.other_text.disabled = true;
}
//-->
</script>
</head>
<body>

<form name="f1" method="post"/>
    <!-- RAPIDSHARE -->
    <input name="RS" type="checkbox" id="rapidshare" onclick="enable_text()" style="vertical-align:middle"/>
    <img src="hosts/RS_icon.png" style="vertical-align:middle"/>
    <!-- MEGAUPLOAD -->
    <input name="MU" type="checkbox" id="megaupload" onclick="enable_text()" style="vertical-align:middle"/>
    <img src="hosts/MU_icon.png" style="vertical-align:middle"/>
    <!-- HOTFILE -->
    <input name="HF" type="checkbox" id="hotfile" onclick="enable_text()" style="vertical-align:middle"/>
    <img src="hosts/Hotfile_icon.png" style="vertical-align:middle"/></br>
   <textarea name="other_text" cols="50" rows="10" id="download" disabled="disabled"></textarea>
</form>

</body>
</html>
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
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.