LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 09-25-2007, 08:54 PM   #1
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,957
Blog Entries: 1

Rep: Reputation: 81
Question JS IE: checkbox.checked doesn't work


I'm creating a checkbox dinamically and setting the "checked" property but it doesn't work on IE. On FF it works flawlessly.

A sample (all the variables were defined with var):
[code]
td = document.createElement("td");
field = document.createElement("input");
field.type="checkbox";
field.name="restrictions" + i + "_" + producto.id;
if (detail != null) {
field.checked=field.restrictions;
}
td.appendChild(field);
tr.appendChild(td);

blah blah
[code]

What's wrong?
 
Old 09-27-2007, 06:07 AM   #2
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 3,992

Rep: Reputation: 478Reputation: 478Reputation: 478Reputation: 478Reputation: 478
Different browsers handle JS code differently, and have different ways of error recovery.

Code:
field.checked=field.restrictions;
What is field.restrictions? It is not a standard property and it does not appear in your code snippet.

Code:
field.name="restrictions" + i + "_" + producto.id
Same here. Are you sure i and producto.id are valid?

IE has a tendency to disable the entire control if any property is incorrect.

jlinkels
 
Old 09-27-2007, 07:27 AM   #3
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,957
Blog Entries: 1

Original Poster
Rep: Reputation: 81
Oh, I made a mistake (here, not in my original code):

Code:
field.checked = details.restrictions;
details.restrictions is a boolean value.
 
Old 09-27-2007, 11:00 AM   #4
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 3,992

Rep: Reputation: 478Reputation: 478Reputation: 478Reputation: 478Reputation: 478
Hmmm JS is a hell to debug that's why I try to avoid it...

Are you sure details.restrictions is a valid Boolean. Did you try to display all values of all fields while debugging? (I usually do this with a message box)

Does the checkbox not appear at all or does it not check/uncheck correctly?

jlinkels
 
Old 09-27-2007, 11:26 AM   #5
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,957
Blog Entries: 1

Original Poster
Rep: Reputation: 81
The checkbox does show up on every browser I tried (IE, FF, Konqeuror), but the only browser where it's not checked is IE.

try this simpler-than-life code:

Code:
<html>
<body onload="initialize()">
<table>
    <tr>
        <td id="node"></td>
    </tr>
</table>
</body>
<script>
    function initialize() {
        var node = document.getElementById("node");
        var check = document.createElement("input");
        check.type="checkbox";
        check.checked = true;
        node.appendChild(check);
    }
</script>
</html>
Can't get simpler than that man. The checkbox does show up on IE, but it's not checked (just tried it).
 
Old 09-27-2007, 02:15 PM   #6
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 3,992

Rep: Reputation: 478Reputation: 478Reputation: 478Reputation: 478Reputation: 478
First do the node.appendChild, then set the object to true. Then it works.


jlinkels
 
Old 09-27-2007, 02:53 PM   #7
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,957
Blog Entries: 1

Original Poster
Rep: Reputation: 81
It sure does! Thanks man.

Here's one more sample of why I say Microsoft is NOT a software company... but a marketting one. Ask me why I hate IE (or Microsoft for that matter).
 
Old 09-27-2007, 03:23 PM   #8
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 3,992

Rep: Reputation: 478Reputation: 478Reputation: 478Reputation: 478Reputation: 478
In case you hadn't noticed yet, different versions of IE behave differently as well.

I am working now on a more or less extended web project, which involves a lot of dynamic page building.

After some initial coding in JS I quickly shifted towards using PHP as much as possible. True, both JS and PHP generated HTML have to be interpreted by the browser. But I found that the quirks in JS are more common often and harder to track down and debug.

So for example this is how I set a check box during page display:

PHP Code:
 <?
function tx_chbox ($s_tx_name$status){
        
//echo "tx_chbox: status: $s_tx_name, $status";
        
if ($status===true) {
                
$s_checked="CHECKED";
        } else {
                
$s_checked="";
        }
        
?>
        <INPUT type="checkbox" <? echo $s_checked?>
                        name="<? echo $s_tx_name?>"
                        value="1"
                        align="left" onchange="submit_page(this.form)"
                        onclick="submit_page(this.form)">
                        <? echo $s_tx_name;
}
?>
Sometimes when you have to do event handling on the client side, you have to use JS.

jlinkels
 
Old 07-27-2011, 02:59 AM   #9
kotev
LQ Newbie
 
Registered: Jul 2011
Posts: 1

Rep: Reputation: Disabled
Thumbs down

Hi guys,

I can't believe that this problem is stil not fiex in IE8 I am totally agree with the statement that Microsoft is not a software company. They developped really buggy products.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question/ answer checkbox for each post schneidz LQ Suggestions & Feedback 1 02-19-2007 02:56 PM
firefox accept cookies checkbox cleared after being checked and FF restarted" skaramanger Mandriva 0 05-10-2006 06:20 PM
PHP,JAVASCRIPT and CheckBox aznita Programming 2 06-17-2005 04:33 AM
3D Acceleration checkbox grayed out itsjustme Linux - General 3 06-24-2003 07:24 PM
apache user/password checkbox jdubu Linux - Networking 1 05-24-2002 07:12 AM


All times are GMT -5. The time now is 01:20 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration