Jump to content

Trigger change event

Go to solution Solved by requinix,

Recommended Posts


I have a page that contain several input boxes and select box

The select box has extra data elements (name_id, group_id, group_id desc)

<div class="form-group mt-1">
	<select class="selectpicker" data-live-search="true" name="name_desc" id="name_desc" title="" style="width:150px;">
		<option value="1 - Name 1" data-name_id="1" data-group_id="1" data-group_id_desc="Group 1">1 - Name 1</option>
		<option value="2 - Name 2" data-name_id="2" data-group_id="2" data-group_id_desc="Second">2 - Name 2</option>
<div class="form-group mt-1">
	<input  type = "hidden" name = "name_id" id="name_id" class="form-control form-control-input" value = "" title="" style="width:100px;">
  	<label class="form-control-placeholder" for="name_id">Name</label>
<div class="form-group mt-1">
	<input type="hidden" name="group_id" id="group_id" class="form-control form-control-input" value=" " title="" readonly="" style="width:100px;"  />
  	<label class="form-control-placeholder" for="group_id">Group</label>
<div class="form-group mt-1">
	<input type="text" name="group_id_desc" id="group_id_desc" class="form-control form-control-input" value=" " title="" readonly="" enabled="false" style="width:180px;" />
	<label class="form-control-placeholder" for="group_id_desc">Description</label>

I populate this boxes by Javascript

$(document).on('select change', '#name_desc', function() 
    var name_id = $(this).find(':selected').data('name_id');
    var name_desc = $(this).find(':selected').text(); 
    var group_id = $(this).find(':selected').data('group_id');                            
    var group_id_desc = $(this).find(':selected').data('group_id') + ' - ' + $(this).find(':selected').data('group_id_desc');

Becaue I populate the input boxes by JS, and I need to do an action when the group_id is changing, I tried to trigger change event:


and the change should call a function

$(".form-control-input").on("change", changefloat);
// and here is the fuction
function changefloat ()

This makes the system to run in circles till I get an error:

Uncaught RangeError: Maximum call stack size exceeded


How can I force the system to trigger the change event without going into that loop?


Thank you

Link to post
Share on other sites
  • Solution

1. Events do not cause recursion, and so shouldn't cause any stack size problems.
2. I don't see any recursion in the code.

What's all the code for this form?

Link to post
Share on other sites

Thank you very much. Your reply helped me to understand that Im not looking at the place of the problem. So I checked, and find out my mistake. I had another function 

$(document).on('select change', '#group_id', function() 

that was suppose to serve other page, and that caused the recursion

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.