Q:

How to test for onchange value?

This gives an error and breaks the function. 

The error says "Cannot read property 'onchange' of undefined" even though I'm trying to test for onchange to prevent an error. 

Here's my function:
function ClearAndRun(element) {
   $el = $("select, input");
   $next = $el.eq($el.index(element) + 1);
   for(i=$el.index($next);i<$el.length;i++) {
     if($next.get(0).onchange != null) {
        $next.val("");
        $next.change;
     }
   $next = $el.eq($el.index(element) + i);
   }
}

<input onchange="ClearAndRun(this)">

I've tried a few different was of testing for an onchange value and they all seem to give that error. Thanks for your help!

A:

So here's what I ended up needing:
function ClearAndRunFuncs(element) {
   $el = $("input[name!=''][onchange!=''], select[name!=''][onchange!='']");
   for(i=$el.index(element)+1;i<$el.length;i++) {
            $el.eq(i).val("");
            $el.eq(i).change();
   }
}

I didn't realize you could put conditions based on attributes on the selector. So this prevents any errors because no fields that are missing onchanges, or even name values are being processed by this function.

