Stephen Forlance
asked on
Jquery driving me nuts...
Hi all,
on this page:
http://bit.ly/2nhZPV8
Can anyone tell me why the modal that is launched when you click "Feedback modal" at the bottom of the page works fine, however the modal that is launched by clicking the red button and then "risk" doesnt.
When you click send its supposed to send the data via POST method and close the modal, same as the feedback modal.
All help is appreciated,
on this page:
http://bit.ly/2nhZPV8
Can anyone tell me why the modal that is launched when you click "Feedback modal" at the bottom of the page works fine, however the modal that is launched by clicking the red button and then "risk" doesnt.
When you click send its supposed to send the data via POST method and close the modal, same as the feedback modal.
All help is appreciated,
The modal seems to be working as you have described.. please clarify.
ASKER
Apologies for not being clearer. The modal displays fine in both cases, however on the modal that appears by clicking Risk, when you click the blue "Send" button nothing happens.
Whereas with the modal that appears by clicking "Feedback Modal form" clicking the blue "Send" button resutls in the form contents being submitted and the modal hidden.
Whereas with the modal that appears by clicking "Feedback Modal form" clicking the blue "Send" button resutls in the form contents being submitted and the modal hidden.
You have id="submit" on all three modal submit buttons... IDs need to be unique. I would suggesting using classes class="submit" and then change the function that runs the form to:
$(document).ready(function(){
$("button.submit").click(function(){
$.ajax({
type: "POST",
url: "up.html",
data: $('form.feedback').serialize(),
success: function(message){
$("#feedback").html(message)
$("#feedback-modal").modal('hide');
},
error: function(){
alert("Error occurred but thats ok, because at least jquery is being called");
}
});
});
});
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Just as a quick test I changed the id to "bing" (a unique ID) and also the one in the function, however its still not working.
ASKER
Brilliant, thank you so much!
You are welcome.
ASKER
Hello,
just noticed a further problem which may be related.
data: $('form.feedback').seriali ze(),
doesnt return the form data, Im guessing because the form is called via ajax. How can I bind it correctly?
just noticed a further problem which may be related.
data: $('form.feedback').seriali
doesnt return the form data, Im guessing because the form is called via ajax. How can I bind it correctly?
It is not due to AJAX - it is most probably because $('form.feedback') is not finding the form - selector may be wrong.
Need to see HTML definition of form.
Need to see HTML definition of form.
ASKER
Where is form.feedback on that page?
You have this
In fact there is no <form> on that page at all - so there is nothing to serialize. For form.serialize() to work there has to be a form involved.
You have this
<div id="feedback">OPP</div>
That is the only element on the page with anything linked to the word feedback. It is clearly not a form so form.feedback is going to give you nothing.In fact there is no <form> on that page at all - so there is nothing to serialize. For form.serialize() to work there has to be a form involved.
ASKER
On the Ajax form the form is:
<form class="feedback" role="form" method="POST" id="feedback" name="feedback">
<form class="feedback" role="form" method="POST" id="feedback" name="feedback">
No the problem is your form
Only one control has a name (section) and all the values in the options are blank.
In order for a control on form to be submitted it HAS TO have a name - no name - no value on the other side - because there is nothing to associate the value to.
The serialize on your AJAX is working - it is just not finding any valid data on the form.
Give your controls names.
Only one control has a name (section) and all the values in the options are blank.
In order for a control on form to be submitted it HAS TO have a name - no name - no value on the other side - because there is nothing to associate the value to.
The serialize on your AJAX is working - it is just not finding any valid data on the form.
Give your controls names.
Define "not working" - I see a modal when I click "risk"