473,591 Members | 2,810 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.che cked == '1')
? $('mycheckbox') .checked = true
: $('mycheckbox') .checked = false;

content = $('mydiv').inne rHTML;

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($('mychec kbox').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 4504


sicapitan wrote:

if (mycheckbox.che cked == '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.che cked)
--

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

(mycheckbox.che cked == '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($('mychec kbox').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.che cked == '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.che cked)
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 26 '06 #3
I think its because actuallly marking the checkbox as
mycheckbox.chec ked = 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.che cked == '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($('mychec kbox').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.che cked == '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.che cked)
--

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=\"check ed\"
/>";
Element.update( "innerstuff ", newstuff);

alert($('inners tuff').innerHTM L);

I get the change with checked="checke d"

but if I

alert($('mystuf f').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.chec ked = 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.che cked == '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($('mychec kbox').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.che cked == '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.che cked)
>
>
--
>
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
1259
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
5285
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 innerHTML is not dynamic. Is there some way to get the most recent selected without traversing through the list's options. Thank you
8
2275
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 receives a variable which basically encapsulates this: <div id="tableid"> <tr>
6
12756
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
1816
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 would like to figure if there's a certain HTML tag inside (like <img src...or any other). I can do it through form.body.value.indexOf("<img") != -1, but I'm looking for a better way that will enable me to extract the element as
2
4930
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 for it indicator = document.getElementById('indicator');
2
1937
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 from slot 3 to slot 6, for example (result: 3- 3) I copy the innerHTML of each div (3-6) into an array. 4) I set the innerHTML of each div (3-6) to now contain the appropriate content from the array. 5) I update the id's of each div (3-6)...
6
27043
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 HTMLDivElement
0
7934
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7870
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8236
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
6639
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5732
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5400
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3891
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1465
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1199
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.