-3

Strange behaviour by IE 7, all other browsers work fine obviously!

If I click the checkbox it returns: object expected.

http://jsfiddle.net/EnYVZ/1/

Any ideas why?

Code:

<div class='tile' onclick=checkbox('95991285')>
<label for='95991285'>
<div>
<input style='vertical-align:middle' type='checkbox' name='frnd[]' value='95991285' id='95991285' checked='checked' />
<img style='vertical-align:middle' src='http://s13.postimage.org/je9k86un7/img.jpg'>
<p>full name</p>
</div>
</label>
</div>​
Mark Belli
  • 740
  • 1
  • 9
  • 17

2 Answers2

2

You don't have a checkbox function defined. You're trying to call a function with this statement

checkbox('1000015175634')

But that function does not exist.

There are a host of other minor problems as well that could probably be helped by running the code through a validator...but that's the big one.

The code should probably look something like this:

<div class="tile" onclick="checkboxAction('a1000015175634')">     
    <input type="checkbox" value="a1000015175634" id="a1000015175634" checked="checked" />     
    <p>name</p>
</div>

<script>
    function checkboxAction(inputBox) {
        // something with inputBox
    }
</script>​  

What exactly is this supposed to be doing?

Beska
  • 12,445
  • 14
  • 77
  • 112
  • Opening curly brackets should *always* go on the line containing the function statement in JavaScript. – danwellman Mar 15 '12 at 14:37
  • @danwellman Why? (I'm not saying they shouldn't...I'm just not sure what the rationale is.) – Beska Mar 15 '12 at 16:55
  • @danwellman Nevermind...a quick search turned up the answer pretty quickly. http://encosia.com/in-javascript-curly-brace-placement-matters-an-example/ Now fixed. – Beska Mar 15 '12 at 16:57
0

I got the solution. I referenced to this thread:

How do I make a checkbox toggle from clicking on the text label as well?

my original code:

<div class='tile' onclick=checkbox('95991285')>
<label for='95991285'>
<div>
<input style='vertical-align:middle' type='checkbox' name='frnd[]' value='95991285' id='95991285' checked='checked' />
<img style='vertical-align:middle' src='http://s13.postimage.org/je9k86un7/img.jpg'>
<p>full name</p>
</div>
</label>
</div>​

I removed this: onclick=checkbox('95991285')

My code was the result of taking more sources and joining them together. It working with all the browsers, except IE 7 and lower and I wanted to understand why.

I am a beginner in javascript and I assumed onclick checkbox was a native function, but it's not.

working code:

<div class='tile'>
<label for='95991285'>
<div>
<input style='vertical-align:middle' type='checkbox' name='frnd[]' value='95991285' id='95991285' checked='checked' />
<img style='vertical-align:middle' src='http://s13.postimage.org/je9k86un7/img.jpg'>
<p>full name</p>
</div>
</label>
</div>​
Community
  • 1
  • 1
Mark Belli
  • 740
  • 1
  • 9
  • 17