Thursday 18 January 2018

javascript - How to handle multiple forms in one page

itemprop="text">

I am working one a page like the
below



            id="first_div">
action='forms_invoice.php' method='post'>
border="0">

>Customer












method='post'>










> id="customers_billto_addr">





Name type="text" value="" id="customers_name">
Bill To


/>





Left
Div(first_div) contains Invoice Data and Right side Div(second_div) is for displaying
additional info or update like displaying a customer info or if it's a new customer,
create a new customer data.



What I want to do
is when submitting a new customer info, i want to the left side div stay unchanged while
submitting right side customer form and after done creating customer log, update
customer list(drop down) in the left side
div(invoice)




The part I don't know is
" do I submit to a page(forms_customer.php) or is there a way to wrap all elements in
second_div and send them with jquery maybe with post method?



Answer




Give each form an identifier (name, id, class
etc...) then target them with jquery and serialize
e.g:



$("#left-side-form").on("submit",function(e){

e.preventDefault();
var formData =
$(this).serialize();
var action = $(this).attr("action");

$.ajax(action, formData, function(response){

//update select
values in left side form here
......

}
});


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...