Ed, here is an excerpt from General Orders, No. 20, dated War Department, Adjutant and Inspector-General's Office, Richmond, December 12, 1861:
1. Volunteers tendering themselves directly to the Confederate Government for three years or the war may be accepted either singly or in companies, battalions, or regiments, organized by the election of their officers. When the officers have been once elected, vacancies are filled by promotion within the same company, battalion, or regiment, except in the lowest grade of company officers, which is filled by election.
2. Where troops have been raised by the several States for the Confederate service, all appointments thereto, except staff appointments, are made and commissions issued by the State authorities under their own laws.
5. The officers of the regimental staff—assistant quartermaster and commissary, surgeon, assistant surgeon, chaplain, and (when not already a lieutenant of the regiment) the adjutant, and the officers of the general staff—are always appointed by the President, through this Department. The recommendation of the commanding officer is respected in making these appointments.
So, to recap, when a regiment is first organized, all line officers up to and including the colonel are elected. Once in service, vacancies among the officers are filled by promotion from within the company or regiment, based on seniority. Except for new junior second lieutenants, which are filled by election.
However, from time-to-time, the War Department could order an election of new officers within a veteran regiment. Normally, this occurred when a regiment was reorganized from a one- or two-year regiment to a three-year regiment.
And, under extraordinary circumstances, the War Department could appoint an officer from outside the regiment. This is what happened when the 14th Arkansas Infantry fell apart in June 1862 in a dispute over extending the men's term of service, and Richmond appointed Frank Powers as colonel, displacing the recently-elected Eli Dodson.