0

I need to grab a variable from a form when the button is clicked, and then process other functions.

This is the error:

jquery.min.js:6 Uncaught RangeError: Maximum call stack size exceeded

Here's the JQuery:

$(document).ready(function(){
var value;
var callMe = function(){
   value = document.getElementsByClassName("instr");
}

$('#container :button').click(function(event){
callMe();
doAjax(value);
});

});

More JQuery. There's more if it's needed.

function doAjax(value) {
    //var value , ajax;
    var ajax;       
    //value = 'CCBOT';  // This variable works when hard coded.

    //Pass the values to the AJAX request and specify function arg for 'done' callback
    ajax = theAjax(value);
    ajax.done(processData);
    ajax.fail(function( jqXHR, textStatus, errorThrown) {
            //Output error information
    });
}

Here's the html form:

<div id="container" class="center">
<form>
<label for="instr">Select Instrument</label>
<select name="instr" id="instr" class="instr" value="">
<option value="WHCBOT">WHEAT-SRW - CHICAGO BOARD OF TRADE</option>
<option value="WHMGE">WHEAT-HRSpring - MINNEAPOLIS GRAIN EXCHANGE</option>
<option value="CCBOT">CORN - CHICAGO BOARD OF TRADE</option>
<option value="OCBOT">OATS - CHICAGO BOARD OF TRADE</option>
</select>    
<input id="button" type="button" value="Get Chart">
</form>
<div id="response-container">
The chart will appear here..
</div>
</div>
3
  • 1
    What is theAjax? Commented Aug 19, 2016 at 17:02
  • Provide your processData function too. Commented Aug 19, 2016 at 17:03
  • The output of document.getElement.... is not the value, it returns the element. Try $('.instr').val() instead Commented Aug 19, 2016 at 17:04

1 Answer 1

1

Your hardcoded test is 'CCBOT', a string value.

Your "live" test is document.getElementsByClassName('instr'), an HTMLCollection.

Since an HTMLCollection is quite clearly not what jQuery is expecting, unexpected behaviour results and the outcome is an unhandled error coming from deep within jQuery's depths.

jQuery doesn't handle type mismatches particularly well, as it tends to be very forgiving (just like HTML is), but in the end it works well with proper input so chances are if an error comes from jQuery, it's because you passed it something wrong.

Did you mean:

value = $(".instr").val();

?

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

1 Comment

Perfect, thank you. And thanks for the explanation. When I did an "alert" it did say "HTMLCollection" but I didn't know what that was. Still not sure but this will help me in the future. Thanks again.

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.