473,387 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 1771
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.