Category Archives: JQuery

Change dropdown values dynamically

We have 2 drop down boxes.

When we select one, we want that second one to be auto-populated with corresponding values to our selection.

This snippet is part of a php code invoked by ajax. It’s purpose is to respond to ajax call in form {“values”:[{“value”:”txt”},{…}]}

Ex: {"values":[{"value":"10","txt":"Aged care service"},{"value":"11","txt":"Social housing"}]}


Ajax call:


Trigger can be:

or using “onChange” event in combobox.

Detect changes in input boxes and persist them via ajax


I have a page dynamically created with many input boxes to serve as comments. They are placed side by side with other elements. See photo.

Basic idea is that on blur event (lose focus) or key press enter to update the input box automatically via ajax (no form submit is necessary).


In my case this is a JSP page and ${} = 32, ${error.comment} =”123″;

JavaScript for enter key:

JavaScript for persist on blur (inputs are id=32 and oldvalue=”123″):

There is room for improvement, but this functionality serves my purpose