I have a form which has multiple buttons for various actions. I am having a weird problem,the jquery onClick does not fire on click of button. Hence the problem. It might be a simple solution, but sorry I am a novice in front end stuff, and none of the questions on stack overflow seemed to be of any help. Below is the html:
<form id="create" action="/service/create" method="POST" style="margin: 0 0 0 0;">
<div class="col-sm-7 ">
//Skipping to buttons directly
<button type=submit class="btn btn-default" id="save">Save</button>
<button type="submit" class="btn btn-default" id="preview">Preview</button>
<button type="submit" class="btn btn-default" id="delete">Delete</button>
</div>
</form>
Below is the jquery code
$(document).ready(function(){
'use strict';
$("#create").on('click', '#save', function (e) {
alert('Save Message');
e.preventDefault();
$.ajax({
url: ADD_ENDPOINT,
data: {'form': $("create").serialize()},
type: 'POST'
});
});
$(document).ajaxError(function( event, jqxhr, settings, thrownError) {
alert("ERROR: "+thrownError);
});
function isErrorOccurred(data){
if(data.indexOf("ERROR")>=0){
alert(data);
return true;
}
else{
return false;
}
}
});
Many of you pointed out, jquery is not being loaded on my page, here is the list of all css/js included in my html, does this look fine or am I missing something
<link rel="stylesheet" href="../css/global-style.css">
<link rel="stylesheet" href="../css/create.css">
<link rel="stylesheet" href="../bootstrap/css/bootstrap.css" />
<link rel="stylesheet" href="../bootstrap/css/bootstrap-fileupload.css" />
<link rel="stylesheet" href="../bootstrap/css/datepicker.min.css" />
<link rel="stylesheet" href="../css/smoothness/jquery-ui-1.11.4.css" type="text/css">
<script src="../jquery/jquery-1.8.3.js" type="text/javascript"></script>
<script src="../bootstrap/js/bootstrap.js" type="text/javascript"></script>
<script src="../bootstrap/js/bootstrap-fileupload.js" type="text/javascript"></script>
<script src="../bootstrap/js/bootstrap-datepicker.js" type="text/javascript"></script>
<script src="../jquery/jquery-ui-1.11.4.js" type="text/javascript"></script>
<script src="../jquery/plugin/jquery.cookie.js" type="text/javascript"></script>
<script src="../js/util.js"></script>
<script src="../js/create.js" type="text/javascript"></script>