473,505 Members | 15,212 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Marking an element as .checked and reading innerHTML

I have this code snippet:

updateProps snippet:

if (mycheckbox.checked == '1')
? $('mycheckbox').checked = true
: $('mycheckbox').checked = false;

content = $('mydiv').innerHTML;

html snippet:

<div id="mydiv">
<input id="mycheckbox" class="checkbox" type="checkbox" value=""
tabindex="14" onchange="(this.checked) ? checkVal = '1' : checkVal =
'0';updateProps(checkVal, 'mycheckbox')" />
</div>

The problem is that when I display the contents of content it doesnt
have 'checked'. But if I alert($('mycheckbox').checked); it says it is
true

Is this a problem with innerHTML not grabbing the correct data or the
checkbox not actually being checked?

Aug 26 '06 #1
4 4494


sicapitan wrote:

if (mycheckbox.checked == '1')
checked is boolean property (assuming that is the checked property of an
input element object in the DOM), no idea why you want to compare that
to a string with one character '1', you probably simply want
if (mycheckbox.checked)
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 26 '06 #2
Sorry, i had :

(mycheckbox.checked == '1')
? $('mycheckbox').checked = true
: $('mycheckbox').checked = false;

if would throw an error

Either way its reading it fine, and writing it fine. well according to
my alerts. in otherwords, if on load i alert($('mycheckbox').checked) i
get 0

when i check the box, and write the variable to a JSON db, then i check
the checkbox its true. then when i go to grab the innerhtml of my div,
it doesnt come through as checked. it sounds like a problem with
innerhtml, but i dont know what could be causing it. im checking the
box, and then grabbing the contents and its not coming through as
checked.

any ideas?

Martin Honnen wrote:
sicapitan wrote:

if (mycheckbox.checked == '1')

checked is boolean property (assuming that is the checked property of an
input element object in the DOM), no idea why you want to compare that
to a string with one character '1', you probably simply want
if (mycheckbox.checked)
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 26 '06 #3
I think its because actuallly marking the checkbox as
mycheckbox.checked = true; acually change the html code, just its
state, so when I get innerHtml its still the old value, thats why. I
would need to update the div with the new contents of a checked
checkbox which would then be able to be read with .innerHTML

sicapitan wrote:
Sorry, i had :

(mycheckbox.checked == '1')
? $('mycheckbox').checked = true
: $('mycheckbox').checked = false;

if would throw an error

Either way its reading it fine, and writing it fine. well according to
my alerts. in otherwords, if on load i alert($('mycheckbox').checked) i
get 0

when i check the box, and write the variable to a JSON db, then i check
the checkbox its true. then when i go to grab the innerhtml of my div,
it doesnt come through as checked. it sounds like a problem with
innerhtml, but i dont know what could be causing it. im checking the
box, and then grabbing the contents and its not coming through as
checked.

any ideas?

Martin Honnen wrote:
sicapitan wrote:

if (mycheckbox.checked == '1')
checked is boolean property (assuming that is the checked property of an
input element object in the DOM), no idea why you want to compare that
to a string with one character '1', you probably simply want
if (mycheckbox.checked)
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 26 '06 #4
ok heres the rundown

If i have this as my html

<div id="mystuff">
<div id="innerstuff">
<input type="checkbox" value="" />
</div>
more stuff
</div>

and I have some javascript:

newstuff = "<input type=\"checkbox\" value =\"\" checked=\"checked\"
/>";
Element.update("innerstuff", newstuff);

alert($('innerstuff').innerHTML);

I get the change with checked="checked"

but if I

alert($('mystuff').innerHTML);

It does not show me the changed information within the innerstuff div.

is this normal?

Bearing in mind I dont want to rebuild the whole div, I just want to
update that field as checked, then grab it entirely with that change,
then load that html into a properties box

sicapitan wrote:
I think its because actuallly marking the checkbox as
mycheckbox.checked = true; acually change the html code, just its
state, so when I get innerHtml its still the old value, thats why. I
would need to update the div with the new contents of a checked
checkbox which would then be able to be read with .innerHTML

sicapitan wrote:
Sorry, i had :

(mycheckbox.checked == '1')
? $('mycheckbox').checked = true
: $('mycheckbox').checked = false;

if would throw an error

Either way its reading it fine, and writing it fine. well according to
my alerts. in otherwords, if on load i alert($('mycheckbox').checked) i
get 0

when i check the box, and write the variable to a JSON db, then i check
the checkbox its true. then when i go to grab the innerhtml of my div,
it doesnt come through as checked. it sounds like a problem with
innerhtml, but i dont know what could be causing it. im checking the
box, and then grabbing the contents and its not coming through as
checked.

any ideas?

Martin Honnen wrote:
sicapitan wrote:
>
>
if (mycheckbox.checked == '1')
>
checked is boolean property (assuming that is the checked property of an
input element object in the DOM), no idea why you want to compare that
to a string with one character '1', you probably simply want
if (mycheckbox.checked)
>
>
--
>
Martin Honnen
http://JavaScript.FAQTs.com/
Aug 26 '06 #5

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

Similar topics

2
1255
by: Jason Morehouse | last post by:
Hello, I want to access an element by passing part of the name to the function... eg: function show_files(item,data) { document.getElementById('row-' + item).innerHTML = data; }
3
5272
by: soup_or_power | last post by:
Hi Sorry about the heading. I have a table with td consisting of lists with <select></select>. When I do a document.getElementById("element").innerHTML I don't see the selected item. IOW, the...
8
2258
by: bennett.matthew | last post by:
Hello all, This is probably an elementary (no pun intended) question, but I've spent all afternoon on it and it's driving me crazy. I have a function which dynamically adds to a table. It...
6
12750
by: libsfan01 | last post by:
hi all! is it possible to change an element type with javacript for example onclick to change a text box to a hidden element or to a textarea? kind regards marc
6
1808
by: Gabriella | last post by:
Hi, I have a textarea, where the user can enter any given string. He can also insert HTML tags, if he/she wishes. Once I obtain the textarea's string as HTML through form.body.innerHTML, I...
2
4924
by: Moses | last post by:
Hi All, Is is possible to catch the error of an undefined element while creating an object for it. Consider we are not having an element with id indicator but we are trying to make the object...
2
1934
by: Stephen Durkin | last post by:
I have some javascript to rearrange a list of elements... 1) Each element (div) is initially given a unique id, the same id of the database record the element represents. 2) User "moves" element...
6
27037
ssnaik84
by: ssnaik84 | last post by:
Hello, I have a HTMLDivElement. I checked its innerHTML property. It has a hidden element (in innerHTML). How I can access the hidden element? For example, fbPartnerName is the...
0
7216
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
7098
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
7303
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
7367
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...
0
7471
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...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4699
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...
0
407
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...

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.