I have a form that its action was initially to refresh the page. but I need a button that will submit the data and change the form's action. I have tried using JavaScript below:
<form id="form1" name="form1" action="" method="post">
Button
<input type="button" class="submit" value="Save" onchange="submitForm()" />
JavaScript
function submitForm(){
document.getElementById('form1').action = <?echo base_url().'index.php/folder/controller/controller_function/';?>;
document.getElementById('form1').submit();
}
When I click the button, nothing happens. I have also tried using if/else statement in the form's action, but that too doesn't work:
<form id="form1" name="form1" action="<?if(isset($_POST['saveButton'])){echo base_url().'index.php/folder/controller/controller_function/';} else{echo "";}?>" method="post">
onclickon the button.