Connecting Tech Pros Worldwide Forums | Help | Site Map

checkbox.disabled

CreativeMind
Guest
 
Posts: n/a
#1: Sep 9 '08
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;
}


SAM
Guest
 
Posts: n/a
#2: Sep 9 '08

re: checkbox.disabled


CreativeMind a écrit :
Quote:
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>
Quote:
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 ?)
Quote:
cbo1.disabled=true;
}
else
cbo1.disabled=false;
Since 'cbo1.value=cbo1val;' has no utility

cbo1.disabled = cibo1.disabled==true;
Quote:
if(!chk2.disabled){
cbo2.value=cbo2val;
cbo2.disabled=true;
}
else
cbo2.disabled=false;
return true;
}
>
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#3: Sep 9 '08

re: checkbox.disabled


CreativeMind wrote:
Quote:
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.
Quote:
if(!chk1.disabled){
I suppose you meant

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

cbo1.disabled = !chk1.checked;

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

cbo2.disabled = !chk2.checked;
Quote:
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
Closed Thread