php - Most straight forward way to retain selected dd option on form submission? -
i have webform has validation functions each field. when submit form, if fails validation, user brought form previous values in input fields , receives error text. working properly.
the 1 field not retain selected value/list of values dropdown gets options via ajax on change of dropdown.
i've read 1 option submit form via ajax i'd rather not go down path.
maybe function on click submit button?
ajax:
function fillsomelistdropdown(val){ $.ajax({ type: 'get', url: 'ajax/somelist.php?q=' + val, success: function(data){ $('#my-id option:not(:first)').remove(); $('#my-id').append(data); } }); }
somelist.php
$q = $_get['q']; $response = sp_things_select_all($q); // generate html foreach ($response $value) { echo '<option class="option-input" value="' . $value['value'] . '">' . $value['value'] . '</option>'; }
assign val variable before passing it.
function fillsomelistdropdown(val){ var val =val; $.ajax({ type: 'get', url: 'ajax/somelist.php?q=' + val, success: function(data){ $('#my-id option:not(:first)').remove(); $('#my-id').append(data); } }); }
Comments
Post a Comment