I installed a new track light to where the old fixture was.I have power to the light track but the on/ off switch does not work anymore and the lights stay on, unless I turn off the circuit breaker. I replaced the switch thinking it was faulty, but did not help. There are 2 cables at the fixture box with a black and white and ground from each cable. I attached black to black ,white to white, ground to ground wires from track just like it was before. Any suggestions? Thanks,
Wires are NOT color coded as well as you think. However, black-white pairs are grouped into cables. That's important. (I'll disregard grounds; all grounds are ground and all go to each other).
One of the black-white pairs in the ceiling is supply power. Black is always hot, white is neutral.
The other black-white pair is a switch loop. When the switch is on, the two wires are shorted to each other. The white is supposed to have a marking on it to indicate that it is not a neutral wire, but that was skipped. This kind of lazy installation is what makes color coding so meaningless.
Disconnect the wires from each other and check which are energized with the power on. Alternately, you can look for the pair whose resistance changes a lot when you throw the switch, but only check resistance with the power off!
The switch-loop white needs to be marked with black tape etc. Code requires we use that one for always-hot. The remaining switch wire (black) will be switched-hot. That goes to the lamp black.
So join the black supply wire and the white-tagged-black switch-loop wire with a wire nut, push it into the back of the box, and never touch it again. These two wires never went to the lamp, and would have been joined just this way, so there was never any reason for you to touch it. I understand the urge to learn electrical by dismantling things, but position information is very important in lazy wiring where nobody marks anything.
If you want to be the opposite of this, I am a huge fan of marking all wires as necessary so their function is clear, and all like colors can simply be joined to each other. In my world, an unmarked white is neutral, an unmarked black is always-hot. Switched-hots are red, unless there's 2 or more in the same box, then blue and yellow. Two yellows in the same cable are the 2 travelers in a 3-way switch circuit. (travelers are interchangeable and there's no need to distinguish them from one another).
The remaining white (from supply) is real neutral to the lamp. The remaining black (from switch) is switched hot to the lamp.
I presume that you just disconnected the 2 wires from the old light, and connected the 2 wires from the new light. Did you do anything to the switch? That sounds like where the problem is. Remember, the switch just breaks the hot wire. "ON" connects the flow in the hot wire, "OFF" cuts that flow. I am presuming you have a basic working knowledge of electricity so you know when to turn the breaker off and on or you know how to work with a hot wire. At the switch box---Isolate your black and white wires that come from your circuit box. These should give you about 120 volts when you put your meter on them. Circuit off-connect your black wire from the circuit box to the bottom screw and secure. Now, secure the black wire going to the light to the top screw and tighten. Now you have the neutral wire from the circuit breaker and the one from the light. Bug these 2 white wires together. Everything should work. Note if this is a 3way, you have a runner wire to deal with. Jim
At this point I think your next step is to verify your wiring, because something does not add up.
I was thinking you might actually have an end of the line switch loop here. If that's the case it wasn't simply three blacks spliced, three whites spliced, three grounds splice in the ceiling box originally. If you put it back together that way, it would be on when the breaker's on, but it would trip with a dead short when the switch is closed, so that part doesn't make fit with an end of the line switch loop; however the switch wasn't working before, so if there's a broken wire in the switch loop, it could make sense.
I'd say the next step is to disconnect and cap all the hots, turn on power, and see which is hot - verify whether the feed comes into the switch box or the ceiling box.