The heart is the abode of intentions which drive people’s actions. Therefore, a Muslim is always required to be watchful of his heart and his intentions. The Prophet (peace and blessings be upon him) said: “Acts are judged by intentions” (al-Bukharia and Muslim). In another hadith he (peace and blessings be upon him) is reported to have said: “Allah does not look at your bodies or your figures but He looks at your hearts and actions.” (Sahih Muslim)
Thus, Muslim jurists paid a lot of attention to the role of intentions and gave lengthy details regarding the Sharia consideration of a person’s intention in determining the validity or invalidity, legitimacy or illegitimacy, lawfulness or unlawfulness of all his deeds and transactions.
To shed more light on this, Sheikh Muhammad Al-`Uthaymeen said:
If changing the intention means changing it from one specific thing to another specific thing, or from something general to something specific, this is not correct. However, if a person changes his intention from something specific to something general, then there is nothing wrong with that.
An example of changing from one specific thing to another specific one is when a person wants to change the Sunnah Prayer of duha to the regular Sunnah of Fajr Prayer which he missed and wants to make it up. He pronounced takbir with the intention of offering two rak`ahs of duha, then he remembered that he did not offer the regular Sunnah of Fajr Prayer, so he wants to change his intention to be offering the regular Sunnah of Fajr Prayer. This is not valid, because the specific regular Sunnah of Fajr Prayer consists of two rak`ahs for which he should have had the intention from the beginning of the Prayer.
Another example is a man who started to pray `Asr Prayer, but while praying he remembered that he had not prayed Zuhr, so he intended this prayer to be Zhuhr Prayer. This is also not valid, because the intention for a specific Prayer must be there from the outset.
With regard to changing the intention from something general to something specific, such as if a person started to offer an unspecific voluntary prayer, then he remembered that he had not prayed Fajr or the Sunnah of Fajr, so he changed his intention to Fajr Prayer or the Sunnah of Fajr – this is also not valid.
As for changing the intention from something specific to something general, such as if one starts praying with the intention that it is the regular Sunnah of Fajr Prayer, then while he is praying he remembers that he has already offered this prayer, in that case he may change his original intention to simply offer a general voluntary prayer.
Another example is that of a man who starts to offer an obligatory Prayer by himself, then a group (jama`ah) comes along, and he wants to change his obligatory Prayer to a voluntary Prayer so that he may cut it short after offering just two rak`ahs, then offer the obligatory Prayer with the group. This is permissible, because he is changing from something specific to something general.
So, the principle is: Changing the intention from one specific thing to another specific thing is not valid; changing it from something general to something specific is not valid; and changing it from something specific to something general is valid.