I'm having more than two forms my page and with one i've there's a script attached that onsubmit it should show a successful message in a div. But when i click on any of the submit buttons on the page, the successful message in the div shows up. this is my code
<script>
$(document).ready(function(){
$("form").on('submit',function(event){
event.preventDefault();
data = $(this).serialize();
$.ajax({
type: "POST",
url: "insert_call_love.asp",
data: data
}).success(function() {
$("#feedback").append("<div class='messages' style='border:1px purple solid; padding:2px; margin:5px;'>You have Loved this photo</div>");
setTimeout(function() {
$(".messages").fadeOut(function(){
$(".messages").remove();
});
}, 1000);
$("input[type=text]").val("");
});
});
});
</script>
and someone told me to change from the one above to this:
<script>
$(document).ready(function(){
$("form3").on('submit',function(event){
event.preventDefault();
data = $(this).serialize();
$.ajax({
type: "POST",
url: "insert_call_love.asp",
data: data
}).success(function() {
$("#feedback").append("<div class='messages' style='border:1px purple solid; padding:2px; margin:5px;'>You have Loved this photo</div>");
setTimeout(function() {
$(".messages").fadeOut(function(){
$(".messages").remove();
});
}, 1000);
$("input[type=text]").val("");
});
});
});
</script>
HTML
<form id="form3" name="form3" method="POST" action="<%=MM_editAction%>">
<input type="image" name="imageField2" id="imageField2" src="imgs/buttons/loveit.png" />
<input name="lemail" type="hidden" id="lemail" value="1" />
<input name="lfname" type="hidden" id="lfname" value="2" />
<input name="lpic" type="hidden" id="lpic" value="3" />
<input name="lresp_email" type="hidden" id="lresp_email" value="4" />
<input name="lwardr" type="hidden" id="lwardr" value="5" />
</form>
specifying the form_id for example my formid is form3 but with that when i even click on submit it doesn't even work
Replace the JQuery 'on submit' from:
$("form3").on('submit',function(event)
to this:
$("#form3").on('submit',function(event)
PS: Make sure that the id is unique in the page
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.