Dropdown not updating when selected via Ajax - php

I have two select dropdowns, regions and towns. If the region is selected, it updates the towns dropdown with the appropriate towns for that region using Ajax.
I am trying to use an imagemap to select the dropdown for region, which should update the towns, but it is not. The value for region dropdown gets selected but the ajax does not fire to update towns. All works fine if not using the imagemap. Is the image map select jQuery below not actually updating the select box the way I think it is? Any ideas?
//ImageMap Selectors
$('area', '#regionmap').click(function(){
$("#region").val($(this).attr('alt'));
});

The onchange event is not fired when an option is selected programmatically. Trigger the event manually by tacking on a call to .change().
$("#region").val($(this).attr('alt')).change();

Related

Yii2 kartik dependent dropdown not changed the selected value with ajax after loading dropdown values with ajax

Want to change selected value of dependent drop-down. After loading drop-down values with ajax in dependent drop down following code is not working
$("#dependentDropDownID").select2("val", data);
Above code working fine on first time load of dependent drop-down.
When we are using kartik select2 drop down then actual id of drop down gone in hidden state so to change value of hidden drop down we have to use "change" event on that id. Use following code for changing selected value of drop down.
$("#dependentDropDownID").val(data).change();
Kartik prepared plugin called DepDrop, which will do all for you.
echo $form->field($model, 'subcat')->widget(DepDrop::classname(), [
'options'=>['id'=>'subcat-id'],
'pluginOptions'=>[
'depends'=>['cat-id'], // id of first input
'placeholder'=>'Select...',
'url'=>Url::to(['/site/subcat']) //url to fetch data
]
]);
Plugin: Kartik DepDrop

Number of dropdowns based on selection of first dropdown

Programming in Bootstrap and PHP I am trying to create a dynamic form which has the following.
User uses a dropdown to select number from 1 to 10.
The page then displays x number of dropdowns.
Each dropdown is the same and displays a list of userID from a MySQL table tblUsers
Once the user makes a selection from each dropdown, it then shows a second dropdown immediately underneath showing a list of videos from a second MySQL table tblVideos. Meaning that the second dropdown is based on the results from the first.
Once all dropdowns have been selected. Submit is pressed and the results are sent as an array to the table tblVideoStored
Any ideas how the PHP and MySQL would be in a simple form..
Based on what you plan to achieve, you may want to look into combining php with ajax (Javascipt). Below are some examples that should set you on the right path
https://www.sitepoint.com/community/t/using-ajax-to-populate-dropdown-menu/4350/2
http://blog.chapagain.com.np/using-jquery-ajax-populate-selection-list/

generating the second drop down list depending on the first list value

I need two drop down list in the same page.The values in the first list are to be fetched from one table and depending on that selected value another set of values should be fetched from another table and show it in the second list.After that both the selected values are to be inserted in a third table on a button click.
Please help me out.
You should add onchange event for the first element and in the onchange handler call an ajax call. In the success handler populate the second dropdown element.

how can i populate the value of dropdownbox while selecting the value of another website in php

I have two dropdown box one for country and second for states
what i should do ? I would select the country from the first dropdown box and
second dropdown box should be filled up with name of the states of concerned country
i want to use jquery and PHP
states and countries are stored in mysql database
How to do dynamic dependent select box using Jquery, Ajax, PHP and Mysql. Dependent select box when a selection is made in a "Parent" box it allow to refresh a "child" box list data.
http://www.9lessons.info/2010/08/dynamic-dependent-select-box-using.html
The below code will be triggered when the selected value of your country drop down list changes.
You could then use a PHP script to return a JSON list of states which will then be populated into your states drop down list.
$('#IdOfYourCountryList').change(function(){
var country = $(this);
$.getJSON("UrlOfYourPHPScript", function(result) {
$.each(result, function() {
options.append($("<option />").val(this.Value).text(this.Key));
});
});
});
this.Key and this.Value refer to the name and value you want for each option, the names may change based on how you structure the JSON.
Tones of examples of this kind of thing. Google is your friend. Here's one example:
http://roshanbh.com.np/2008/01/populate-triple-drop-down-list-change-options-value-from-database-using-ajax-and-php.html

how to get the dropdown value?

Hi i am using dropdown for display the timezone.The timezone values are come from database.Whenever the user change the value I need to alert the new timezone.For example if user change the time GMT+5.30 to GMT+6.30 then I want to alert GMT+6.30.Here the the dropdown values coming as an array?What can I do to get the values?
If you're using select and you have set values for your options, you can:
$("select#dropdown").change(function(){
alert($(this).val());
});
To do this, you need the jQuery framework. http://www.jquery.com/
checkout http://www.texotela.co.uk/code/jquery/select/ plugin for handling select element, very handy.

Categories