Most screenwriters start their careers writing on speculation. That means they write without being hired and paid for it. Selling such a script calls to sell a "spec-script". Only a handful of spec-scripts are produced every year.
Many of them also work as "script doctors," attempting to change scripts to suit directors or studios; for instance, studio management may have a complaint that the motivations of the characters are unclear or that the dialogue is weak.
Script-doctoring can be quite lucrative, especially for the better known writers. David Mamet and John Sayles, for instance, fund the movies they direct themselves, usually from their own screenplays, by writing and doctoring scripts for others. In fact, some writers make very profitable careers out of the script doctoring food chain, being the ninth or tenth writer to work on a piece; in many cases, working on projects that never see exposure to an audience of any size.
A few screenwriters have also found work by selling a treatment (approximately 10-30 pages) or synopsis (usually 1-2 pages), of their screenplay even if it isn't completed yet. This is however extremely rare.
One of the most important elements in bringing an idea to fruition for a studio to produce is attaching the right screenwriter to the project. Often projects are sold to studios who then assign their own preferred screenwriters to complete the script or write the final draft.
Most professional screenwriters are unionized and are represented by organizations such as the Writers Guild of America, East. The WGA is final arbiter on awarding writing credit for projects under its join.