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.

2
  • 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? Commented Jul 25, 2013 at 13:39
  • duplicate of Simple example doesn't work on JSFiddle Commented Jul 25, 2013 at 13:57

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

7 Comments

So I've tried this but it only disabled it doesn't re-enable jsfiddle.net/Arandolph0/jxjW9/11
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.
@AprilRandolph: The .disabled property must be set to a boolean! Your strings are both truthy. You probably want something like jsfiddle.net/jxjW9/12
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....
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)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.