Passing conditional referral code based on URL string and form selection

Passing conditional referral code based on URL string and form selection

How can we pass the appropriate referral code in the following scenario based on the URL string and color selected?

Form select (Colors):
  • Red
  • Blue
  • Black
  • White

Scenario 1:
If user accesses page with a URL string that includes any CLR, such as testing.com/?CLR=somethingHere, then mktrfl="default"

Scenario 2:
If user accesses page with following URL string (testing.com/), 
and selects "Red",
then mktrfl="groupred"

Scenario 3:
If user accesses page with following URL string (testing.com/), 
and selects "Blue",
then mktrfl="groupblue"

Scenario 4:
If user accesses page with following URL string (testing.com/), 
and selects "Black" or "White",
then mktrfl="default"

I need to dynamically create a value for the hidden field "mktrfl". So far, I have this:
  1. <input type="hidden" value="" name="mktrfl"> <select name="color"> <option value="">--Please Select--</option> <option value="red">Red</option> <option value="blue">Blue</option> <option value="black">Black</option> <option value="white">White</option> </select>