Home › Forums › Back End › How to dynamically submit changes in a form or in a content editable table?
- This topic is empty.
-
AuthorPosts
-
March 5, 2013 at 12:22 am #43148
justinweb
MemberHi everyone,
I am looking for the best solution for dynamically updating changes on a MySQL Database every time someone makes a change to a record.
Here is some context:
I am building a large CRM for a client. I would like a record to be modified without the need of a separate edit.php page or submit button. I have tried using the onchange in javascript but it keeps refreshing the page and does not provide a good user experience.
Thanks for the help!
March 5, 2013 at 12:24 am #126962justinweb
MemberOh and I am organizing the information in both html inputs and tables.
March 5, 2013 at 12:25 am #126963DADE
ParticipantAjax is the answer. If you are using jQuery look at this:
http://api.jquery.com/jQuery.ajax/
// JS
$(form).on(‘submit’, function(e) {e.preventDefault();
var firstName = $(input).val(),
lastName = $(input).val();$.ajax(
type: ‘post’,
url: ‘submit.php’,
data: { name : firstName, surname : lastName }
).done(function(html) {
$(element).html(html);
});// in submit.php you’ll get this $_POST value, in our case $_POST, $_POST;
});March 5, 2013 at 12:40 am #126960justinweb
MemberAnd because its using Ajax it doesn’t refresh the page and does this all in the background right?
March 5, 2013 at 12:42 am #126961DADE
ParticipantYeap.
http://en.wikipedia.org/wiki/Ajax_(programming)
See this .done() function will return html result of your submit.php file in ‘html’ (in this case) variable. So you can select element and replace it’s content with $(element).html(html).
And e.preventDefault() will disable default form submit. So your page won’t start loading after you click .
March 5, 2013 at 12:52 am #126966justinweb
MemberHypothetically, if I wanted the piece of code you wrote to upload a change in an input once the user clicks out of it, would I do:
$(form).on(‘blur’, function(e) {}
And then send the info to a submit.php which handles the data transmission behind the scene? Then I guess I could just have a little notification popup to confirm the changes.
March 5, 2013 at 12:57 am #126970DADE
ParticipantExactly.
March 5, 2013 at 12:58 am #126971justinweb
MemberNice, much easier then I thought! Thanks a whole lot!
March 5, 2013 at 1:03 am #126973JohnMotylJr
ParticipantNow this thread is the definition of TEAMWORK!! Nice work!!
March 8, 2013 at 11:39 am #127487justinweb
MemberIf I didn’t want to use JQuery, what would be the equivalent of the first code in JS ?
March 8, 2013 at 12:00 pm #127489justinweb
MemberOh never mind, I think it will be much simpler using JQuery.
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.