Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7808403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:07:32+00:00 2026-06-02T03:07:32+00:00

Ok, here goes my first question on here. Setup: We use a javascript based

  • 0

Ok, here goes my first question on here.

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.

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.

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.

Here is my code (I apologize in advance for any newbie mistakes):

//script at bottom of original or tool-served control html page template
<script type="text/javascript">
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' && typeof _tool_exp_ids[0] !== 'undefined') {
     valForTool();
  }  else {   
     originalValidation();
  };   
});
</script>
//end script on control or original template  

//script on tool-served variation html template - will run after the above script
<script type="text/javascript"> 
$(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');
 });
</script>
// end script on variation template

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:07:34+00:00Added an answer on June 2, 2026 at 3:07 am

    Shortening it down a bit, it seems like your just doing this:

    <script type="text/javascript">
    $(function(){
       if (typeof _tool_exp_ids !== 'undefined' && typeof _tool_exp_ids[0] !== 'undefined') {
          var variationId = _tool_exp[_tool_exp_ids[0]].combination_chosen;
          if (variationId == 1) {
              $.getScript('js/scripts.js', function() {runSecond();});
          }
       }else{   
              $.getScript('js/scripts.js', function() {runSecond();});
       }
    
       function runSecond() {
          $('#project_info input[type=submit]').removeAttr('disabled').unbind();
          $.getScript('js/scripts2.js');
          $('.input_text').parent().addClass('contact_field');
       }
    });
    </script>
    

    Now looking at that, it’s obvious that both scripts are running no matter what conditions are met in those if/else statements, and I don’t really get what it is your trying to do, but the first thing i would do, is to add some console.logs to see if those if/else statements are working like they are supposed to, and then figure what scripts should be loaded under which conditions etc ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first question to stackoverflow so here it goes... I use cruise
This is my first question here on stack overflow. i need help on a
Here goes my first question. First of all I'm new with Java and still
This is my first question on here so here goes.... I've got an issue
My first question so here it goes. My goal is to have a simple
First question, here goes nothing... I'm trying to add a new entry to my
My first question on this site, here goes: I am working on a tutorial
so here goes my first real coding question ever on the web since normally
Ok here goes. This is my first ever wicket application and I'm trying to
This is probably a trivial question for most but here goes... I am using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.