How to use JavaScript to change the form action [duplicate]
function chgAction( action_name )
{
if( action_name=="aaa" ) {
document.search-theme-form.action = "/AAA";
}
else if( action_name=="bbb" ) {
document.search-theme-form.action = "/BBB";
}
else if( action_name=="ccc" ) {
document.search-theme-form.action = "/CCC";
}
}
And your form needs to have name
in this case:
<form action="/" accept-charset="UTF-8" method="post" name="search-theme-form" id="search-theme-form">
Try this:
var frm = document.getElementById('search-theme-form') || null;
if(frm) {
frm.action = 'whatever_you_need.ext'
}
If you're using jQuery, it's as simple as this:
$('form').attr('action', 'myNewActionTarget.html');