Anonymous
Форма Javascript отправляет действие изменения с атрибутами attr
Сообщение
Anonymous » 15 янв 2025, 13:23
Я хочу изменить действие атрибута моей формы в цели, чтобы динамически получать следующую страницу. В javascript моя переменная action получает правильное значение, но страница все равно не загружается. Он отлично работает, если я вручную возвращаю правильное «значение», но не работает, когда я использую jQuery('#select_program').children().filter(':selected').text().replace(/\s+ /g, '-').toLowerCase(),, чтобы сделать это динамически.
Вот моя форма (на php):
Код: Выделить всё
public function form_creation() {
$html = '';
$html .= '';
$html .= '';
$html .= __('Language', 'mon-plugin');
$html .= '';
$html .= '';
$html .= '';
$html .= '';
$html .= __('Program', 'mon-plugin');
$html .= '';
$html .= '';
$html .= '';
$html .= '';
$html .= __('Country', 'mon-plugin');
$html .= '';
$html .= '';
$html .= '';
$html .= '';
$html .= __('City', 'mon-plugin');
$html .= '';
$html .= '';
$html .= '[i] $html .= htmlspecialchars(json_encode($this->backend_select_category));
$html .= '"/>';
$html .= '';
$html .= '[/i]';
$html .= __('Search', 'mon-plugin');
$html .= '';
$html .= '';
return $html;
}
Вот мой JavaScript:
Код: Выделить всё
jQuery('#search_projects').submit(function() {
var selection_value = [
jQuery('#select_langue').val(),
jQuery('#select_program').val(),
jQuery('#select_country').val(),
jQuery('#select_city').val()
];
var selection_display = [
jQuery('#select_langue').children().filter(':selected').text().replace(/\s+/g, '-').toLowerCase(),
jQuery('#select_program').children().filter(':selected').text().replace(/\s+/g, '-').toLowerCase(),
jQuery('#select_country').children().filter(':selected').text().replace(/\s+/g, '-').toLowerCase(),
jQuery('#select_city').children().filter(':selected').text().replace(/\s+/g, '-').toLowerCase()
];
jQuery(this).attr('action', function() {
if (selection_value[1] !== 'nd') {
var action = selection_display[1];
if (selection_value[2] !== 'nd') {
action += selection_display[2];
if (selection_value[3] !== 'nd') {
action += selection_display[3];
}
}
} else {
var action = 'search_program';
}
return action;
});
});
Спасибо за помощь!
Подробнее здесь:
https://stackoverflow.com/questions/463 ... attributes
1736936581
Anonymous
Я хочу изменить действие атрибута моей формы в цели, чтобы динамически получать следующую страницу. В javascript моя переменная action получает правильное значение, но страница все равно не загружается. Он отлично работает, если я вручную возвращаю правильное «значение», но не работает, когда я использую jQuery('#select_program').children().filter(':selected').text().replace(/\s+ /g, '-').toLowerCase(),, чтобы сделать это динамически. Вот моя форма (на php): [code]public function form_creation() { $html = ''; $html .= ''; $html .= ''; $html .= __('Language', 'mon-plugin'); $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= __('Program', 'mon-plugin'); $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= __('Country', 'mon-plugin'); $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= __('City', 'mon-plugin'); $html .= ''; $html .= ''; $html .= '[i] $html .= htmlspecialchars(json_encode($this->backend_select_category)); $html .= '"/>'; $html .= ''; $html .= '[/i]'; $html .= __('Search', 'mon-plugin'); $html .= ''; $html .= ''; return $html; } [/code] Вот мой JavaScript: [code]jQuery('#search_projects').submit(function() { var selection_value = [ jQuery('#select_langue').val(), jQuery('#select_program').val(), jQuery('#select_country').val(), jQuery('#select_city').val() ]; var selection_display = [ jQuery('#select_langue').children().filter(':selected').text().replace(/\s+/g, '-').toLowerCase(), jQuery('#select_program').children().filter(':selected').text().replace(/\s+/g, '-').toLowerCase(), jQuery('#select_country').children().filter(':selected').text().replace(/\s+/g, '-').toLowerCase(), jQuery('#select_city').children().filter(':selected').text().replace(/\s+/g, '-').toLowerCase() ]; jQuery(this).attr('action', function() { if (selection_value[1] !== 'nd') { var action = selection_display[1]; if (selection_value[2] !== 'nd') { action += selection_display[2]; if (selection_value[3] !== 'nd') { action += selection_display[3]; } } } else { var action = 'search_program'; } return action; }); }); [/code] Спасибо за помощь! Подробнее здесь: [url]https://stackoverflow.com/questions/46330539/javascript-form-submit-change-action-with-attr-attributes[/url]