jeudi 27 février 2020

Defining checkbox based on value in URL query string

Traffic is driven to one of our pages with a query string that includes a 'campaign' value. There are 12 different campaign values possible. Here's an example:

www4.foo.com/p3423?campaign=30&cid=4401&lid=342&etrack=54tr88

When the campaign value is equal to 30, like in the example above, the checkbox needs to appear with the following label:

Category: Television

For the label, the category would be defined in the 'prefix' variable.

var prefix = "Category: ";

The checkbox code I'm working with looks like this:

<li id="showCampaignCheck"> 
<div class="checkbox">
  <input type="checkbox" id="campaign_topic" name="campaign_topic_mediaTelevision" value="on" class="check custom-class" oninvalid="this.setCustomValidity('Please make selection')">
  <label for="subscription"><span>Category: Television</span>
  </label>
</div>
</li>

So each category has to have the following defined:

Category: 30
topic   : prefix + "Television",  
idAttr  : "tv",
name    : "tv"

These values would be used to create the checkbox.

What is an efficient way to code this out, preferably using jQuery?




Aucun commentaire:

Enregistrer un commentaire