I am just starting to study all this and I am completely confused. Google, but give a completely different answer. I have a select. It selects a city and in accordance with the city in the second select, information about the PSCs (that is, the cities of this city) is issued. How to send for processing data. I will process a PHP-script.
4 answers
Well, somehow it should look like this:
HTML:
<select id="select1"> <option value="1">Один</option> <option value="2">Два</option> <option value="3">Три</option> </select> <select id="select2"> <option value="0">Выберите сначала в первом</option> </select> $(document).ready(function(){ $("#select1").change(function(){ $.ajax({ type : 'GET', url : 'path/to/php_file', data : { select1: $(this).val() }, success : $("#select2").html }); }) });
PHP:
for($i=0; $i<$_GET['select1']; $i++){ echo '<option value="'.$i.'">'. $_GET['select1'] . " - " . $i ."</option>"; }
- <option disabled> Select first in first </ option> - Vfvtnjd
- The option cannot do this, only like this: <select id = "select2" disabled = "disabled">, but then it will be necessary to write success: ... success: function (data) {$ ("# select2"). attr ("disabled", false) .html (data); } ... - MuFF
|
$.ajax({ type : 'POST', url : 'path/to/handler', data : $('form').serialize(), success : function(data) { alert(data) } });
- oneIt should be noted that using [jQuery] [1] greatly simplifies this procedure (a very cool thing if someone does not know =)) [complete jQuery tutorial ajax] [2] [1]: jquery.com [2]: api.jquery .com / jQuery.ajax - MaxXx1313
- Who as if all that is needed is working with ajax, then personally I like superagent most of all - Zowie 8:39 pm
|
jQuery.post () - read, it will be useful.
The same in Russian.
- If I understood correctly, the author says that he needs to load the list of options into the second select depending on the first. And for such a POST load, it is somehow out of place to use. - MuFF
|
$("#form_id").submit()
|