Rep. Joshua Eilberg (D-Pa.) was indicted yesterday on charges of receiving compensation illegally after helpin a Philadelphia hospital obtain a $14.5 million federal grant.

The one-count indictment was returned by a Philadelphia grand jury.

It came exactly two weeks before the Nov. 7 election in which the 57-year-old Eilberg, seeking his seventh House term, is locked in tight contest with Republican challenger Charles F. Dougherty, a state senator from Philadelphia.

the indictment also came nearly a year after Republican prosecutor David W. Marston touched off a national controversy by charging that Eilberg was trying to get President Carter to fire him. Yesterday's indictment grew out of an investigation that Marston's officce initiated.

Neither Eilberg nor his spokesman could be reached for comment, but last month the congressman denied a similar charge when the House Committee on Standards of Official Conduct said he received more than $103,000 from his law firms in connection with the hospital grant. He said then that he welcomed a hearing on the issue.

Eilberg is the third congressman to be indicted in recent months.

Rep. Daniel J. Flood (D-Pa.) was indicted here and in Los Angeles on 13 counts involving bribery, perjury and conspiracy to trade his influence in Congress for money and back stocks in several indictments unrelated on the issue.

Flood was mentioned yesterday in the Eilberg count and in a separate 19-count indictment that the Philadelphia grand jury also handed down yesterday in the same case, but Flood was not indicated again.

Earlier this month, Rep. Charles C. Diggs Jr. (D-Mich.) was convicted on charges of diverting more than $60,000 in staff salaries to pay his personal office expenses.

Three other Congressmen - Edward R. Roybal, Charles H. Wilson and John H. McFall, all California Democrats - were reprimanded by the House this month for their roles in the South Korea influence-buying scheme.

Yesterday's indictment charged that between April 1975 and December 1977 Eilberg received unspecified compensation from the Hahnemann Hospital through his law firms for his and their services - and those of Flood - in securing the $14.5 million grant.

The Community Service Administration, the federal anitpoverty agency, awarded the money to the hospital in 1975 to finish construction of an addition.

U.S. Attorney Peter Vaira of Philadelphia said in a telephone interview that the indictment did not detail how much Eilberg allegedly received because "it's a matter of proof. We won't get into particulars until we go to trial."

Asked why the indictment came so close to the election, he replied, "We have one rule - whenever an investigation is finished, we bring an indictment. To do otherwise would be unfair."

Eilberg was indicted under a conflict-of-interest statute that differs from bribery. Vaira explained that bribery requires proof of "corrupt intention - it's taking money to take a drive. In this case all we have to prove is that he's a congressman and he got money."

Taking compensation illegally by a member of Congress carries a maximum punishment of two years in prison and a $10,000 fine. Bribery carries a maximum of 15 years in prison and a $20,000 fine.

The 19-count indictment issued at the same time charges three other men connected with the hospital-addition project with devising a scheme to defraud several individuals and businesses during the planning and construction phases.

Named were E. Wharton Shober, 51, of New York City, former president of Hahnemann Hospital; George L. Guerra, 41, of Glen Moore, Pa., and John P. Dixon, 48, of Frackville, Pa. Guerra was president of Capital Investment Development Corp., which had the contract to monitor the hospital construction, and Dixon was a major investor in CIDC, the indictment said.

One count said that Shober "did directly and indirectly, corruptly give, offer and promise" $10,000 to Flood in return for his aid in getting the federal grant. Another count said Guerra and Dixon "did, directly and indirectly, corruptly give, offer and promise" $20,000 to Flood's former aide, Stephen B. Elko, for help in getting CDIC the contract to monitor the construction project.

A source familiar with the case said Flood and Elko were not indicted because there is a question about whether they actually received the money. Asked if Flood is cooperating in the case, Caira exclaimed, "Hell, no."

Eilberg apparently had no connection with the Shober-Guerra-Dixon case, a source said.

Eilberg's name surfaced in the Hahnemann project late last year when Vaira's predecessor, Marston, charged that the congressmen tried to have him removed as U.S. Attorney in Philadelphia.