Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nihalarya's avatar

Select a resource and display other resource according to the selected one.

I want to make an admin panel in which user will have different restaurants and all the other resources will depend on the restaurant which is selected. Can I create a dropdown at the top which selects the restaurants and rest of the resources are displayed according to the selected restaurant?

0 likes
1 reply
vincent15000's avatar

Hello @nihalarya,

Yes it's possible. I do this using javascipt.

You have your view.

<select id="restaurant_id" name="restaurant_id">...</select>
<div id="other_fields"></div>

Then in your javascript / jquery code, you have to add an event on the select change.

$("#restaurant_id").on("change", function() {
	var restaurant_id = $("#restaurant_id").val();
	// According to the restaurant_id, you decide here what to display
	// If you have to retrieve some data from the database, you can try a get or post ajax
	$.post(
		url: URL,	// URL according to your routes, the data are sent by the controller
		{
			restaurant_id: restaurant_id,
			other_data: OTHER_DATA,		// other data if you need
		},
	)
	.done(function(data) {			// data sent by the controller
		$("#other_fields").html(data);
	})
	.fail(function() {
		alert("An error has occured !");
	});
});

Tell me how it works ...

Please or to participate in this conversation.