0

Why do I get a function undefined http://jsfiddle.net/Arandolph0/8eukN/3/

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<form id="frmcheckbxs" >    
  <c:set var="recordCount" value="2"/>
  <input type="checkbox" id="chkRefId${recordCount}" onclick="checkRushed    ('frmcheckbxs','chkRefId','2')" />
  <input type="checkbox" id="chkRefId1" />
</form>

I checked and it doesn't look to be something like a typo it appears to be functional.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
April_Nara
  • 1,024
  • 2
  • 15
  • 39
  • Your jsFiddle is set to execute `onLoad`, which means your JavaScript code will be put inside of `window.onload = function () { /* CODE HERE */ };`. Does that look global and available to you? – Ian Jul 25 '13 at 13:39
  • duplicate of [Simple example doesn't work on JSFiddle](http://stackoverflow.com/questions/5431351/simple-example-doesnt-work-on-jsfiddle) – Bergi Jul 25 '13 at 13:57

1 Answers1

2

You have set JSFiddle to wrap all your JavaScript in an onload event handler function.

checkRushed is defined inside that function, so it is scoped to that function and not available as a global.

Bind your event handlers with addEventListener (or the helper function of your choice if you are using a library that abstracts that) instead of using intrinsic event attributes.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • So I've tried this but it only disabled it doesn't re-enable http://jsfiddle.net/Arandolph0/jxjW9/11/ – April_Nara Jul 25 '13 at 13:52
  • 1
    The event object doesn't have a value, an HTMLInputElement does, so you want to be using `this` not `e`. The value of the input will never be `off` though, you haven't set a value on it. You want to examine the `checked` property, which will be a boolean. – Quentin Jul 25 '13 at 13:55
  • @AprilRandolph: The `.disabled` property must be set to a boolean! Your strings are both truthy. You probably want something like http://jsfiddle.net/jxjW9/12/ – Bergi Jul 25 '13 at 13:59
  • Also, what do you do when you have a dynamic list of checkboxs that you want to add the eventListener to? Ex. checkbox1, checkbox2, etc.... – April_Nara Jul 25 '13 at 14:20
  • Either use a loop, or assign the event handler to an ancestor element and capture it when it bubbles (using `event.target` to figure out which element was hit) – Quentin Jul 25 '13 at 14:24
  • Umm… the `
    ` itself should do.
    – Quentin Jul 25 '13 at 16:42
  • @Quentin In IE the type, when checking, to process an attachEvent is undefined. How do I narrow the element tree to verify/validate my object? – April_Nara Jul 25 '13 at 19:32