I don't know about mothballs, but salt will kill fleas. Salt and boric acid (borax) kill flea adults, larvae, and eggs by desiccating them. "Desiccate" means "dry out". They turn fleas into desert mummies.
You should sprinkle the salt all over the carpet and leave it for a few days. Then vacuum and throw away the bag. When your house is infested with fleas, you need to get the vacuum bag out of the house after vacuuming or the fleas will escape the bag and return to the carpet.
Putting salt in the vacuum bag, and then vacuuming, will only kill the fleas that get vacuumed into the bag. The fleas still in the carpet will be unharmed.
You should sprinkle the salt all over the carpet and leave it for a few days. Then vacuum and throw away the bag. When your house is infested with fleas, you need to get the vacuum bag out of the house after vacuuming or the fleas will escape the bag and return to the carpet.
Putting salt in the vacuum bag, and then vacuuming, will only kill the fleas that get vacuumed into the bag. The fleas still in the carpet will be unharmed.