I need to change the form action URL depending on the body class of the page. So far I have
$('document').ready(function () {
if ($('body').hasClass('hosting')) {
$('#quoteForm').attr('action', 'hostingURL');
}
});
and that works perfectly. But I need to expand it to include more body classes. I tried
$('document').ready(function () {
if ($('body').hasClass('hosting')) {
$('#quoteForm').attr('action', 'hostingURL');
}
elseif ($('body').hasClass('workspace')) {
$('#quoteForm').attr('action', 'workspaceURL');
}
else{}
});
but it isn't working. Any suggestions appreciated.
on("click", function(e){ e. preventDefault(); $('#contactsForm'). attr('action', "/test1"). submit(); });
jQuery is just JavaScript, don't think very differently about it! Like you would do in 'normal' JS, you add an event listener to the buttons and change the action attribute of the form. In jQuery this looks something like: $('#button1').
form action javascript. In an HTML form, the action attribute is used to indicate where the form's data is sent to when it is submitted. The value of this can be set when the form is created, but at times you might want to set it dynamically.
add white space in elseif
like else if
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With