473,569 Members | 2,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

checkbox.disabl ed

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.g etElementById(" _ctl0_ContentPl aceHolder2_chkF inance");
var
chk2=document.g etElementById(" _ctl0_ContentPl aceHolder2_chkM ortgage");
var
cbo1=document.g etElementById(" _ctl0_ContentPl aceHolder2_ddlF inance");
var
cbo2=document.g etElementById(" _ctl0_ContentPl aceHolder2_ddlM ortgage");
var cbo1val=cbo1.va lue;
var cbo2val=cbo2.va lue;
if(!chk1.disabl ed){
cbo1.value=cbo1 val;
cbo1.disabled=t rue;
}
else
cbo1.disabled=f alse;
if(!chk2.disabl ed){
cbo2.value=cbo2 val;
cbo2.disabled=t rue;
}
else
cbo2.disabled=f alse;
return true;
}

Sep 9 '08 #1
2 1783
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==fa lse;
c2.disabled = c2.disabled==fa lse;
}
</script>
<a href="javascrip t:check();">che ck</a>
</html>
function checkFinance(){

var
chk1=document.g etElementById(" _ctl0_ContentPl aceHolder2_chkF inance");
var
chk2=document.g etElementById(" _ctl0_ContentPl aceHolder2_chkM ortgage");
var
cbo1=document.g etElementById(" _ctl0_ContentPl aceHolder2_ddlF inance");
var
cbo2=document.g etElementById(" _ctl0_ContentPl aceHolder2_ddlM ortgage");
var cbo1val=cbo1.va lue;
var cbo2val=cbo2.va lue;
if(!chk1.disabl ed){
cbo1.value=cbo1 val;
don't understand ... cbo1.value is not changed (what the using ?)
cbo1.disabled=t rue;
}
else
cbo1.disabled=f alse;
Since 'cbo1.value=cbo 1val;' has no utility

cbo1.disabled = cibo1.disabled= =true;
if(!chk2.disabl ed){
cbo2.value=cbo2 val;
cbo2.disabled=t rue;
}
else
cbo2.disabled=f alse;
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.g etElementById(" _ctl0_ContentPl aceHolder2_chkF inance");
var
chk2=document.g etElementById(" _ctl0_ContentPl aceHolder2_chkM ortgage");
var
cbo1=document.g etElementById(" _ctl0_ContentPl aceHolder2_ddlF inance");
var
cbo2=document.g etElementById(" _ctl0_ContentPl aceHolder2_ddlM ortgage");
var cbo1val=cbo1.va lue;
var cbo2val=cbo2.va lue;
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.disabl ed){
I suppose you meant

if (!chk1.checked)
{
cbo1.value=cbo1 val;
That does not make sense to me.
cbo1.disabled=t rue;
}
else
{
cbo1.disabled=f alse;
}

cbo1.disabled = !chk1.checked;

would suffice, and it would be more efficient and easier to maintain.
if(!chk2.disabl ed){
if (!chk2.checked)
{
cbo2.value=cbo2 val;
See above.
cbo2.disabled=t rue;
}
else
{
cbo2.disabled=f alse;
}

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.getEle mentById() 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
2089
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 the span tag in the case of a checkbox or a radiobutton. Effectively, these controls are not disabled in netscape.
1
6203
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: function radioClicked(index) { document.table_config_form.my_checkbox.disabled = true;
1
3496
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 ? <li>ABACAVIR SULFATE</li> <INPUT NAME="ingredient0" TYPE=checkbox VALUE="ABACAVIR SULFATE"><br> <input name="ABACAVIR SULFATE AMOUNT" type="radio"...
4
3386
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 (i=0;i<form.elements.length;i++){ THATname = form.elements.name.split("-"); if (Sname.length==1){ if (THATname==Sname){
2
3116
by: Sebi | last post by:
Hello all is it possible to add a checkbox in a DataGrid for Boolean Data? Thanks in advance
5
3112
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. One of the controls is a checkbox, which, when clicked, displays a hidden panel containing controls whose input are used for filtering query...
3
4483
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 the latest value of the checkbox. Does this sound like a posibility and if so how can I force the server to get the new value from the page? ...
5
9155
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 this property to ViewState? If needed, I can give you more info on exactly what I'm trying to do. Thanks,
6
23834
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 and forth with no problems. using disabled = true or disabled = false If I start out as:
3
1487
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" cellspacing="3"> <thead> <tr class="tableheader" style="height: 15px;">
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8122
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7673
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7970
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.