Independent variable is the variable that is manipulated in an experiment while the dependent is the outcome variable. Wiith this in mind therefore you could see that that, depending on the study design, knowledge and attitude could be dependent or independent in situations as you exactly described.
Two good user friendly reference books would be Creswell (2009), and Frankfort-Nachmias & Nachmias ( ) at a more advanced level. These are detailed below, you may find them useful.
Creswell, J. (2009). Research design: Qualitative, quantitative, and mixed methods approaches (Laureate Education, Inc., custom Ed.). Thousand Oaks, CA: Sage Publications
Frankfort-Nachmias, C., & Nachmias, D. (2008). Research methods in the social sciences (7th Ed.). New York: Worth.