By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,414 Members | 1,050 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,414 IT Pros & Developers. It's quick & easy.

CheckBox value on HTML page triggered from Code Behind

P: n/a
Dear all,

I have checkbox on my webform, and I want that when I click my checkbox, it
should change status between true or false...

Here is my code,

// Code Behind
CheckBox1.Attributes["onClick"] = "JSGeneratePackageID()";

How to make my CheckBox has value? Because in the html page my checkbox
doesn't have any value? I assign checkbox value to a label, but it doesn't
show up.

// HTML Code
function JSGeneratePackageID()
{
document.getElementById("Label1").innerText =
document.getElementById("CheckBox1").innerText; // Didn't work.
}

Because I need to use checkbox value to switch the checkbox value, whenever
it has 'click' event.., like this...

//HTML Code
if (document.getElementById("CheckBox1").innerText = = "False")
document.getElementById("CheckBox1").innerText = "True";
document.getElementById("Label1").innerText = "True";
else
document.getElementById("CheckBox1").innerText = "False";
document.getElementById("Label1").innerText = "False";
Thx,
Julius F
Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
document.getElementById("Label1").value =
(document.getElementById("CheckBox1").selected ? "true" : "false");

InnerText is not applicable to "<input ..." elements. It's mostly to
spans and text areas, where you have an inner-text.
CHeers,
Gaurav Vaish
http://mastergaurav.org
http://mastergaurav.blogspot.com
----------------------------

Nov 19 '05 #2

P: n/a
Hi Mr. Gaurav, I have follow your instructions and thanks for your help, the
checkbox change status when has a first click on it, but.. when I repeatedly
clicking on it, it doesn't change value anymore.., here is my code:

// HTML
function JSGeneratePackageID()
{
if (document.getElementById("chb_vIsDefect").selected )
document.getElementById("chb_vIsDefect").selected = false; // Can't
work, how to change checkbox value?
document.getElementById("lbl_vValue").innerText = "false";
else
document.getElementById("chb_vIsDefect").selected = true; // Can't
work, how to change checkbox value?
document.getElementById("lbl_vValue").innerText = "true";
}

// Code Behind
chb_vIsDefect.Attributes["onClick"] = "JSGeneratePackageID()";
Thx,
Julius F

================================================== =

"MasterGaurav" <ga**********@gmail.com> wrote in message
news:11*********************@l41g2000cwc.googlegro ups.com...
document.getElementById("Label1").value =
(document.getElementById("CheckBox1").selected ? "true" : "false");

InnerText is not applicable to "<input ..." elements. It's mostly to
spans and text areas, where you have an inner-text.
CHeers,
Gaurav Vaish
http://mastergaurav.org
http://mastergaurav.blogspot.com
----------------------------

Nov 19 '05 #3

P: n/a
The property you are looking for is "checked".

docment.all["chb_vIsDefect"].checked = true;

I am not sure if the click event bubbles to actually turn the checkbox, so
you might want return true from this function, so the click event could
bubble.

bill

"Julius Fenata" <id****@gmx.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi Mr. Gaurav, I have follow your instructions and thanks for your help, the checkbox change status when has a first click on it, but.. when I repeatedly clicking on it, it doesn't change value anymore.., here is my code:

// HTML
function JSGeneratePackageID()
{
if (document.getElementById("chb_vIsDefect").selected )
document.getElementById("chb_vIsDefect").selected = false; // Can't work, how to change checkbox value?
document.getElementById("lbl_vValue").innerText = "false";
else
document.getElementById("chb_vIsDefect").selected = true; // Can't work, how to change checkbox value?
document.getElementById("lbl_vValue").innerText = "true";
}

// Code Behind
chb_vIsDefect.Attributes["onClick"] = "JSGeneratePackageID()";
Thx,
Julius F

================================================== =

"MasterGaurav" <ga**********@gmail.com> wrote in message
news:11*********************@l41g2000cwc.googlegro ups.com...
document.getElementById("Label1").value =
(document.getElementById("CheckBox1").selected ? "true" : "false");

InnerText is not applicable to "<input ..." elements. It's mostly to
spans and text areas, where you have an inner-text.
CHeers,
Gaurav Vaish
http://mastergaurav.org
http://mastergaurav.blogspot.com
----------------------------


Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.