javascript formdata.display into a link

1 replies
Hey Guys,
So I use aweber for my email lists and I got some javascript code from them to pass the personalized options of the subscriber onto a webpage. The javascript looks like this.
Code:
<script type="text/javascript">
 var formData = function() {
     var query_string = (location.search) ?  ((location.search.indexOf('#') != -1) ? location.search.substring(1,  location.search.indexOf('#')) : location.search.substring(1)) : '';
    var elements = [];
     if(query_string) {
       var pairs = query_string.split("&");
       for(i in pairs) {
          if (typeof pairs[i] == 'string') {
              var tmp = pairs[i].split("=");
              elements[unescape(tmp[0])] = unescape(tmp[1]);
          }
       }
    }
     return {
        display: function(key) {
            if(elements[key]) {
              document.write(elements[key]);
            } else {
              document.write("<!--If desired, replace everything  between these quotes with a default in case there is no data in the  query string.-->");
            }
        }
    }
 }();
 </script>
So I want to display the url of the download page they need to go to in order to get the product. I want them all on one list so I am associating the url of the download page as a custom field on the sign up form. Like this:
Code:
<input type="hidden" name="custom downloadurl" value="http://letsdownloadstuff.com" />
So if they signed up under my ficticious dog product sign up form it would look like this:
Code:
<input type="hidden" name="custom downloadurl" value="http://letsdownloaddogstuff.com" />
So the download url is changing according to what sign up for they sign up under.
Then when they confirm their subscription they are taken to a page were they find their download link. I then ( according to aweber ) put the above javascript code in the <head> and this code were I want the custom field to appear
Code:
<script type="text/javascript">formData.display("custom downloadurl")</script>
Then on my download page it says something like, thanks for purchasing the product go to this page and get your product:
http://letsdownloadstuff.com
So depending on the signup for they signup on the download url will change. Is this making sense?
The main deal is I want to know how to make the download url into a link that when they click on it, it takes them to the download url specific to whatever sign up form they signed up under. Cause right now it is just plain text in my firefox browser.
I am sure I'm going to have to clarify things but I appreciate any help you can give me.



by the way the urls given are just examples and are not my sites.
#formdatadisplay #javascript #link
  • Profile picture of the author Mark Crawford
    I ended up asking one of my programmer friends to take a look at it and he gave me a solution. Here is the solution.

    Code:
    <a href="#" id="download-link">Download Here</a>
    
    
    <script type="text/javascript">
       formData.display("custom sorry");
    </script>
    "custom sorry" is my personalized form data that is being passed into this page from aweber. I made custom sorry my download link url. So whatever web form the subscriber signed up under they get the right download link and they all stay on the same list cause you can have multiple web forms under one list.

    The javascript function:

    Code:
    <script type="text/javascript">
    
    
    var formData = function() {
    
    
         var query_string = (location.search) ?  ((location.search.indexOf('#')  != -1) ? location.search.substring(1,  location.search.indexOf('#')) :  location.search.substring(1)) : '';
        var elements = [];
    
    
        if(query_string) {
           var pairs = query_string.split("&");
           for(i in pairs) {
              if (typeof pairs[i] == 'string') {
                  var tmp = pairs[i].split("=");
                  elements[unescape(tmp[0])] = unescape(tmp[1]);
              }
           }
        }
    
    
        return {
            display: function(key) {
                if(elements[key]) {
                  download_link = document.getElementById("download-link");
                  download_link.setAttribute('href', elements[key]);
                } else {
                  document.write("Something went wrong. Please email me at youremail@email.com for your download link.");
                }
            }   
        }
    
    
    }();
    
    
    </script>
    This has worked rather well for me. I hope it helps you.
    {{ DiscussionBoard.errors[5254817].message }}

Trending Topics