472,973 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,973 software developers and data experts.

checkbox.disabled

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
2 1750
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ashish Shridharan | last post by:
Hi All, Has anyone ever tried disabling a checkbox or a radiobutton web server control in netscape ? While a textbox and a button control renders disabled, .NET adds the disabled attribute to...
1
by: David Wake | last post by:
I have two radio buttons and two checkboxes in a form. I'm trying to write some code so that when a radio button is selected, its corresponding checkbox is disabled. My code looks like this: ...
1
by: John Mullen | last post by:
I want to take the following HTLM and use javascript to turn on radio buttons if checkbox is checked, can I do this with javascript (maybe onClick or an array) or do i need a server side script ?...
4
by: feanor | last post by:
I need to select children checkboxes when selecting the parent one. This is my function: function SelectChildrens(checkbox_name){ form = document.forms; Sname = checkbox_name.split("-"); for...
2
by: Sebi | last post by:
Hello all is it possible to add a checkbox in a DataGrid for Boolean Data? Thanks in advance
5
by: Greg Hurlman | last post by:
I've got a very simple ASCX page, where once someone finishes a section and clicks the "Next >" button, the section they just finished is disabled, and the next section appears below it, and so on....
3
by: Marc Castrechini | last post by:
I have a page that changes an <ASP:Checkbox value based on a user entered value in a textboxm using client side Javascript. After my submit is fired the value for the chkMyCB.checked does not get...
5
by: Leo J. Hart IV | last post by:
Hello, I'm hoping someone can help me out. I was wondering if the Enabled property of a CheckBox or RadioButton server control is stored in the ViewState. If not, is there some way to to add...
6
by: tshad | last post by:
I am trying to disable and enable a checkbox from javascript. The problem is that if the checkbox starts out as: <input id="Override" type="checkbox" name="Override"/> I can change it back...
3
by: AshishMishra16 | last post by:
Hi Friends, What is the way to iterate the Table and Make all the input types editable on the click of a checkbox. Here is what My Requirement is : <table id="adSearchTable"...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.