I have this piece of code to intercept the click of a submit button but does not work at all
JS
$('#deleteDescriptionButtonId3').click(function () {
alert('deleting description...');
$('#productFormId').attr('method', 'post');
$('#productFormId').attr('action', '/nicinc/desc/del/3');
});
HTML
<textarea id="descriptions0.text" name="descriptions[0].text" class="form-control" rows="4">
ASDADS
</textarea>
<span class="clear space10"> </span>
<button id="deleteDescriptionButtonId3" class="btn btn-primary" type="submit">
Delete description
</button>
答案 0 :(得分:1)
Try to change type="submit"
to type="button"
.
答案 1 :(得分:0)
You can use event.preventDefault();
Here is an example
$( "#deleteDescriptionButtonId3" ).click(function( event ) {
event.preventDefault();
alert('deleting description...');
$('#productFormId').attr('method', 'post');
$('#productFormId').attr('action', '/nicinc/desc/del/3');
$('#form_id').submit();
});
Here #form_id is the form that you are submitting