The oxygen atom requires 2 electrons to complete its valance shell. Hydrogen is special in that it can eighter give or take one electron and still be stable. So hydrogen gives its electron to oxygen, and two hydrogens fill up all of oxygen's valance shell, and it forms water.