I previously answered about the Republican Party here, and you can see more details there, but this case is covered by Rule 9(a):
The Republican National Committee is hereby authorized and empowered to fill any and all vacancies which may occur by reason of death, declination, or otherwise of the Republican candidate for President of the United States or the Republican candidate for Vice President of the United States, as nominated by the national convention, or the Republican National Committee may reconvene the national convention for the purpose of filling any such vacancies.
For the Democrats, this is covered by rule VII(G) in their Call for Convention:
Filling a Vacancy on the National Ticket:
the event of death, resignation or disability
of a nominee of the Party for President or
Vice President after the adjournment of the
National Convention, the National
Chairperson of the Democratic National
Committee shall confer with the Democratic
leadership of the United States Congress
and the Democratic Governors Association
and shall report to the Democratic National
Committee, which is authorized to fill the
vacancy or vacancies.
In short: The RNC members can choose a new candidate themselves or reconvene the convention. The DNC members simply choose a candidate.