473,386 Members | 1,795 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,386 software developers and data experts.

neat javascript?? vsnet2k3

hey all,

is there a neater way to write the following javascript code? Basically
there just 3 controls on my webform a button,checkbox,radio button. if you
check the checkbox it just enables the radiobutton. the button is just there
for postback testing.

<script type="text/javascript">
var rb
var cxb
function InzSr(){
rb=document.getElementById("RadioButton1")
cxb=document.getElementById("CheckBox1")
rb.disabled=(cxb.checked==true)?false:true
}

function test(cxb){
rb.disabled=(cxb.checked==true)?false:true
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<P>
<asp:CheckBox id="CheckBox1" runat="server"
onClick="test(this)"></asp:CheckBox>
<asp:RadioButton id="RadioButton1" runat="server"></asp:RadioButton></P>
<P>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button></P>
<script type="text/javascript">InzSr();</script>
</form>
</body>
Aug 20 '06 #1
2 1142
one simplification i can spot is as follows:

instead of:
rb.disabled=(cxb.checked==true)?false:true
just use:
rb.disabled = !cxb.checked;

the use of the conditional operator isn't necessary here, because the
expression inside the brackets evaluates to a boolean anyway.

also, just to be picky :) the "==true" is unnecessary because ".checked" is
already a boolean property.

hope this helps
tim

"rodchar" <ro*****@discussions.microsoft.comwrote in message
news:E3**********************************@microsof t.com...
hey all,

is there a neater way to write the following javascript code? Basically
there just 3 controls on my webform a button,checkbox,radio button. if you
check the checkbox it just enables the radiobutton. the button is just
there
for postback testing.

<script type="text/javascript">
var rb
var cxb
function InzSr(){
rb=document.getElementById("RadioButton1")
cxb=document.getElementById("CheckBox1")
rb.disabled=(cxb.checked==true)?false:true
}

function test(cxb){
rb.disabled=(cxb.checked==true)?false:true
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<P>
<asp:CheckBox id="CheckBox1" runat="server"
onClick="test(this)"></asp:CheckBox>
<asp:RadioButton id="RadioButton1" runat="server"></asp:RadioButton></P>
<P>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button></P>
<script type="text/javascript">InzSr();</script>
</form>
</body>

Aug 21 '06 #2
thank you very much.

"Tim_Mac" wrote:
one simplification i can spot is as follows:

instead of:
rb.disabled=(cxb.checked==true)?false:true
just use:
rb.disabled = !cxb.checked;

the use of the conditional operator isn't necessary here, because the
expression inside the brackets evaluates to a boolean anyway.

also, just to be picky :) the "==true" is unnecessary because ".checked" is
already a boolean property.

hope this helps
tim

"rodchar" <ro*****@discussions.microsoft.comwrote in message
news:E3**********************************@microsof t.com...
hey all,

is there a neater way to write the following javascript code? Basically
there just 3 controls on my webform a button,checkbox,radio button. if you
check the checkbox it just enables the radiobutton. the button is just
there
for postback testing.

<script type="text/javascript">
var rb
var cxb
function InzSr(){
rb=document.getElementById("RadioButton1")
cxb=document.getElementById("CheckBox1")
rb.disabled=(cxb.checked==true)?false:true
}

function test(cxb){
rb.disabled=(cxb.checked==true)?false:true
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<P>
<asp:CheckBox id="CheckBox1" runat="server"
onClick="test(this)"></asp:CheckBox>
<asp:RadioButton id="RadioButton1" runat="server"></asp:RadioButton></P>
<P>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button></P>
<script type="text/javascript">InzSr();</script>
</form>
</body>


Aug 29 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Frances Del Rio | last post by:
http://www.emol.com/especiales/cocina_chilena/comida.asp this page is so neat (goes in pop-up..) how was this done? how do you give a layer (or div, I guess) a semi-transparency so you can still...
4
by: Kerberos | last post by:
Check it out here: http://www.amazon.com pass your mouse over the top tab "SEE ALL 31 Product Categories" and see the nice menu. Is there a way to do it easily with CSS? I checked out the code, and...
8
by: Tracker3000 | last post by:
(please stop deleting :), or tell me why you are, but this is where I want the thread) How do I make an image gallery where there are about 20 thumbnails and when you click on one, it blows it up...
1
by: Alex Karuso | last post by:
I found this quick CSS search site the net. You type style name, it gives you style options and help right away. Neat. I thought I'd share it with others - http://www.gotapi.com
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.