Skip to content
Advertisement

How to display select option values base on the first option

I am using Codeigniter 3.1.1. I want City option to display base on the value selected with State option. Actually the City select option does not populate automatically when State option is selected. I tried to link the latest jQuery but still, it doesn’t work. Your help is highly appreciated.

MyController.php

JavaScript

View:

JavaScript

Ajax:

JavaScript

Advertisement

Answer

You’ve not specified what problem you face when you run your code or what is the output or what is the error, so, we’ve no way of knowing what the real issue is. However, I’m sharing a working code (an excerpt from my project) of what you want; I’ve also changed the values according to your needs.

This follows a different approach as AJAX expects HTML to be returned and that HTML is formed in PHP controller rather than on success in jQuery and then simply added to the desired id.

AJAX

JavaScript

Controller

JavaScript

See if it helps you.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement