Link to home
Start Free TrialLog in
Avatar of synergiq
synergiqFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Too much recursion in javascript

I wrote a little javascript snippet to hide/show a div when a checkbox is unticked/ticked. Please see the code snippet for my code.

I know I've gone wrong somewhere because FireBug in FireFox gives me a "too much recursion" error. But I don't know enough about javascript to see where I've gone wrong.
<script type="text/javascript" charset="utf-8">
$(function showdiv(check_name){
	$(check_name).toggle(150);
	return false;
});
</script>
 
<p class="userdisp_alt"><input type="checkbox" class="user_check" name="fld_FirstName_check" onclick="showdiv('#fld_FirstName')"/><label for="fld_FirstName">First Name</label></p>
<p id="fld_FirstName" class="udf_textbox"><input type="text" name="fld_FirstName" /></p>

Open in new window

Avatar of Badotz
Badotz
Flag of United States of America image

I don't see where any HTML element has an id of "#fld_FirstName". I see "fld_FirstName", so perhaps this is your problem?
Avatar of synergiq

ASKER

If I change it from onclick="showdiv('#fld_FirstName')" to onclick="showdiv('fld_FirstName')" then the toggle stops working.

At the moment, the javascript works but in IE I get a 'Stack Overflow' error and in FireFox it says that there is too much recursion. I've removed this function from the page and although the toggle stops working the stack overflow error goes away so I'm sure it's this function that is causing it.

I've googled the problem and I'm getting results like this: http://stackoverflow.com/questions/639862/too-much-recursion-error-in-jquery-1-3-2 saying that it is a problem with the javascript code but I am unsure what I have to change to make it work.
Not being familiar with jquery, I would suggest delving into the documentation to be sure you are using the correct syntax.
ASKER CERTIFIED SOLUTION
Avatar of jfromanski
jfromanski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That is perfect, thank you!