By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,302 Members | 1,816 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,302 IT Pros & Developers. It's quick & easy.

checkbox.disabled

P: n/a
hi
i have following code but problem is that when i debug both checkboxes
have disabled property always false whether it is checked or
unchecked..thx for help.
function checkFinance(){

var
chk1=document.getElementById("_ctl0_ContentPlaceHo lder2_chkFinance");
var
chk2=document.getElementById("_ctl0_ContentPlaceHo lder2_chkMortgage");
var
cbo1=document.getElementById("_ctl0_ContentPlaceHo lder2_ddlFinance");
var
cbo2=document.getElementById("_ctl0_ContentPlaceHo lder2_ddlMortgage");
var cbo1val=cbo1.value;
var cbo2val=cbo2.value;
if(!chk1.disabled){
cbo1.value=cbo1val;
cbo1.disabled=true;
}
else
cbo1.disabled=false;
if(!chk2.disabled){
cbo2.value=cbo2val;
cbo2.disabled=true;
}
else
cbo2.disabled=false;
return true;
}

Sep 9 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
SAM
CreativeMind a écrit :
hi
i have following code but problem is that when i debug both checkboxes
have disabled property always false whether it is checked or
unchecked..thx for help.
Try this demo :

<html>
<form>
<input name="cbo1" type="checkbox" value="1">
<input name="cbo2" type="checkbox" value="2">
</form>
<script type="text/javascript">
function check() {
var c1 = document.forms[0].cbo1;
var c2 = document.forms[0].cbo2;
c1.disabled = c1.disabled==false;
c2.disabled = c2.disabled==false;
}
</script>
<a href="javascript:check();">check</a>
</html>
function checkFinance(){

var
chk1=document.getElementById("_ctl0_ContentPlaceHo lder2_chkFinance");
var
chk2=document.getElementById("_ctl0_ContentPlaceHo lder2_chkMortgage");
var
cbo1=document.getElementById("_ctl0_ContentPlaceHo lder2_ddlFinance");
var
cbo2=document.getElementById("_ctl0_ContentPlaceHo lder2_ddlMortgage");
var cbo1val=cbo1.value;
var cbo2val=cbo2.value;
if(!chk1.disabled){
cbo1.value=cbo1val;
don't understand ... cbo1.value is not changed (what the using ?)
cbo1.disabled=true;
}
else
cbo1.disabled=false;
Since 'cbo1.value=cbo1val;' has no utility

cbo1.disabled = cibo1.disabled==true;
if(!chk2.disabled){
cbo2.value=cbo2val;
cbo2.disabled=true;
}
else
cbo2.disabled=false;
return true;
}
Sep 9 '08 #2

P: n/a
CreativeMind wrote:
i have following code but problem is that when i debug both checkboxes
have disabled property always false whether it is checked or
unchecked..thx for help.
function checkFinance(){

var
chk1=document.getElementById("_ctl0_ContentPlaceHo lder2_chkFinance");
var
chk2=document.getElementById("_ctl0_ContentPlaceHo lder2_chkMortgage");
var
cbo1=document.getElementById("_ctl0_ContentPlaceHo lder2_ddlFinance");
var
cbo2=document.getElementById("_ctl0_ContentPlaceHo lder2_ddlMortgage");
var cbo1val=cbo1.value;
var cbo2val=cbo2.value;
These two variables are unnecessary, and performance would also improve
slightly if you used the references right-hand side only when they are needed.
if(!chk1.disabled){
I suppose you meant

if (!chk1.checked)
{
cbo1.value=cbo1val;
That does not make sense to me.
cbo1.disabled=true;
}
else
{
cbo1.disabled=false;
}

cbo1.disabled = !chk1.checked;

would suffice, and it would be more efficient and easier to maintain.
if(!chk2.disabled){
if (!chk2.checked)
{
cbo2.value=cbo2val;
See above.
cbo2.disabled=true;
}
else
{
cbo2.disabled=false;
}

cbo2.disabled = !chk2.checked;
return true;
}
As for the rest of your code, you should be using the `elements' collection
of form objects instead of several document.getElementById() calls. And you
would probably need a server-side alternative that double-checks the
submitted data.
HTH

PointedEars

P.S.
The pronoun `I' and the first letter of a sentence must be a capital letter
in proper English.
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Sep 9 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.