javascript - Action always going to Index using submit() -
in view, i'm using function, submitform(action)
submit form on button click. 1 of many buttons use function. action
parameter indicate controller method use.
the function seems generate correct action attribute (the path correct in console), directed index
method rather action
parameter.
the button:
<input type="button" value="save only" id="save" onclick="submitform('saveonly')" />
the function:
function submitform(action) { var $form = $("#myform"); $form.action = ("/area/mycontroller/" + action); $form.submit(); }
you're not accessing 'action' attribute of form itself, jquery selector result, in order code work, need access dom element inside selector $form[0]. recommend stick jquery, you're using it!. below working code jquery selectors.
<form id="myform"></form> <input type="button" value="save only" id="save" data-action="saveonly" />
<script> $('#save').click(function(){ var action = $(this).data('action'); var $form = $("#myform"); $form.attr('action', "www.google.com?q=" + action); $form.attr('method', 'get'); $form.submit(); }); </script>
Comments
Post a Comment