checkbox.disabled

C

CreativeMind

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_ContentPlaceHolder2_chkFinance");
var
chk2=document.getElementById("_ctl0_ContentPlaceHolder2_chkMortgage");
var
cbo1=document.getElementById("_ctl0_ContentPlaceHolder2_ddlFinance");
var
cbo2=document.getElementById("_ctl0_ContentPlaceHolder2_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;
}
 
S

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>
function checkFinance(){

var
chk1=document.getElementById("_ctl0_ContentPlaceHolder2_chkFinance");
var
chk2=document.getElementById("_ctl0_ContentPlaceHolder2_chkMortgage");
var
cbo1=document.getElementById("_ctl0_ContentPlaceHolder2_ddlFinance");
var
cbo2=document.getElementById("_ctl0_ContentPlaceHolder2_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;
 
T

Thomas 'PointedEars' Lahn

CreativeMind said:
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_ContentPlaceHolder2_chkFinance");
var
chk2=document.getElementById("_ctl0_ContentPlaceHolder2_chkMortgage");
var
cbo1=document.getElementById("_ctl0_ContentPlaceHolder2_ddlFinance");
var
cbo2=document.getElementById("_ctl0_ContentPlaceHolder2_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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,356
Latest member
Tommyhotly

Latest Threads

Top