I’m working on a travel planning form that adjusts based on the selected nationality. For example, if someone picks a country like India, the form should display whether they need an electronic visa for places like Sri Lanka, and maybe show a short message or guide link.

I’m using JavaScript to detect changes in a <select> dropdown and send that to a PHP file via AJAX. The PHP checks a list and responds with JSON.

But I’m running into a few issues:

Sometimes the JSON response is empty, even though it works in the browser.

Other times, the DOM update doesn’t reflect the new message.

What’s the best structure to manage these types of dynamic, country-specific conditions without hardcoding everything in JS?

Any feedback appreciated — especially if you’ve done something similar for multi-country forms.

✅ This version:

Avoids links and commercial terms

Focuses on technical workflow (AJAX, PHP, JSON)

Mentions <link removed by moderator> as an example, not a pitch

I have moved your post into the web development forum instead of the advertising/marketing forum where it was and tagged it appropriately.

Can you please provide the Javascript code as well as PHP code that is buggy so that we can help diagnose this for you. For example, if the JSON response is empty, it is most likely because of a bug in the PHP code. If the DOM doesn't reflect the new message, then that's a javascript issue.

What’s the best structure to manage these types of dynamic, country-specific conditions without hardcoding everything in JS?

I would store them in some form of database that PHP would have access to, and pass back ot javascript. None of the specific conditions should be hardcoded in javascript. I'm confused what you mean by hardcoding country-specific conditions in javascript, and yet using AJAX to have the PHP check a list. Do you mean the country-specific conditions are hardcoded in PHP instead of PHP utilizing a database?

Please provide your code :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.