Serve alternate external Javascript file depending on if elements are defined or not in the page
<p>Ok, here goes my first question on here.</p>

<p>Setup: We use a javascript based tool to A/B test our landing page designs. I need version A (control) to link to one external javascript file, and version B (variation) to link to an alternate javascript file. </p>

<p>Goal: to have an internal js script at the bottom of the control that looks to see if the tool is in fact serving A or B, and if true, which one was served. The result indicates which external script should be linked.</p>

<p>Issue: regardless of if the tool is in fact serving A or B, the original script is linked first, then if the tool is detected, the appropriate script is linked after that.</p>

<p>Here is my code (I apologize in advance for any newbie mistakes):</p>

<pre><code>//script at bottom of original or tool-served control html page template
&lt;script type="text/javascript"&gt;
valForTool = function () {
  var variationId = _tool_exp[_tool_exp_ids[0]].combination_chosen;
  if (variationId == 1) {
     var newScript = document.createElement('script');
     newScript.type = 'text/javascript';
     newScript.src = 'js/scripts.js';
     document.body.appendChild(newScript);
   };
}
originalValidation = function () {
  var newScript = document.createElement('script');
   newScript.type = 'text/javascript';
   newScript.src = 'js/scripts.js';
   document.body.appendChild(newScript);
}
$(function(){
  if (typeof _tool_exp_ids !== 'undefined' &amp;&amp; typeof _tool_exp_ids[0] !== 'undefined') {
     valForTool();
  }  else {   
     originalValidation();
  };   
});
&lt;/script&gt;
//end script on control or original template  

//script on tool-served variation html template - will run after the above script
&lt;script type="text/javascript"&gt; 
$(function() {
     $('#project_info input[type=submit]').removeAttr('disabled');
     $('#project_info').unbind();
     var newScript = document.createElement('script');
     newScript.type = 'text/javascript';
     newScript.src = 'js/scripts2.js';
     document.body.appendChild(newScript);  
     $('.input_text').parent().addClass('contact_field');
 });
&lt;/script&gt;
// end script on variation template
</code></pre>

<p>Any ideas as to what I'm doing wrong? Did I provide enough information? Thanks! I love this site as a reference for my questions, but this is my first time actually posting one.</p>
