1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Newbie desperate for help please

Discussion in 'JavaScript' started by hcbeggar, Jan 25, 2009.

  1. #1
    Ok, I am desperate to find this answer if any coder can help me I would be grateful.
    So here is my situation:
    I figured out how to pass variables from one page to another and to a url. So my next question is:
    Is there a way to pass variables out of my url or from a section of the web page and place it into the subid section of an affiliate link.

    So there is no confusion at all this is my goal.
    1) Have a person fill out form on h**p://www.surveybeggar.com/test.html (It's a bit crude looking right now)

    a)So I fill out my Name: Eric & My Email: test@test<dot>com

    2) when that person fills out the form they are redirected to a new page with the URL:
    h**p://www.surveybeggar.com/test2.html?FirstName=Eric&Email=test@test.com

    a) as you can see the first name & email are added to the domain but also on that page I have passed those two variables as text.

    Now here is what I want to have done....
    There are two affiliate banner ads on this page. I have an affiliate banner with the following code:

    <a href="http://partners.pantheranetwork.com/z/3945/CD5923/&subid1=email"><img src="http://partners.pantheranetwork.com/42/5923/3945/&subid1=email" alt="" border="0"></a>

    What I want to do is trade that word email that is in red with the email address from the url (in this case - test@test<dot>com) or that is already on the page that I have passed from a previous page. How can I add the email address where I have put the word email in this code? I essentially want to add the email variable that is in the url &/or on the page above and have it automatically populate itself as a sub id in the banner ads.
    Can someone please help me learn how to do this or give me the snippet in java script to add to the end of my affiliate banner code that will populate the email variable?

    If you want to see what I have done, please view source of the following website:

    h**p://www.surveybeggar.com/test2.html?FirstName=Eric&Email=test@test.com


    thanks for any help. Will offer $10 via paypal, alert pay, or revolutionmoney exchange to anyone who can help!
     
    hcbeggar, Jan 25, 2009 IP
  2. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    hmmm...

    your first url looks like this:

    http://partners.pantheranetwork.com/42/5923/3945/&subid1=<?php echo $_GET['Email']; ?>
    Code (markup):
    which means for some reason it isn't parsing the php. Fix that problem it should work. also do the same thing for the second banner.

    its better to use php to pull get values, if you use javascript (like you are in some cases) you need to use the decodeURIComponent.
     
    MMJ, Jan 25, 2009 IP
  3. hcbeggar

    hcbeggar Member

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    sorry, i took the php code out but didnt publish it....that code is out cause the php doesnt work. It shouldnt be there now.

    how do I use the decodeURIComponent? can you teach me that, please?
     
    hcbeggar, Jan 25, 2009 IP
  4. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Its a (much) better solution to use PHP, you sure you can't use it?

    Here is a javascript function I wrote to emulate php's $_GET variable:

    (function(){
        var parts = location.href.indexOf('?') >= 0 ? location.href.split('?')[1].split('&') : [];
        window.GET = [];
        for (var i = 0, l = parts.length, t; i < l; i++){
            t = decodeURIComponent(parts[i]).split('=');
            GET[t[0]] = t[1];
        }
    })();
    PHP:
    so to get the Email variable:

    GET['Email']
    PHP:
     
    MMJ, Jan 25, 2009 IP
  5. hcbeggar

    hcbeggar Member

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    Got, this must be like working with an absolute amateur monkey for you...but I really appreciate it.

    ok, so its supposed to look like this?:

    (function(){ var parts = location.href.indexOf('?') >= 0 ? location.href.split('?')[1].split('&') : [Email]; window.GET = [Email]; for (var i = 0, l = parts.length, t; i < l; i++){ t = decodeURIComponent(parts).split('='); GET[t[0]] = t[1]; }})();

    <a href="http://partners.pantheranetwork.com/z/3945/CD5923/&subid1=GET['Email']"><img src="http://partners.pantheranetwork.com/42/5923/3945/&subid1=GET['Email']" alt="" border="0"></a>

    I think I am still messing this up.
     
    hcbeggar, Jan 25, 2009 IP
  6. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #6
    no, you don't change the function.

    add this to your <head>
    
    
      <script type="text/javascript">
    	(function(){
    		var parts = location.href.indexOf('?') >= 0 ? location.href.split('?')[1].split('&') : [];
    		window.GET = [];
    		for (var i = 0, l = parts.length, t; i < l; i++){
    			t = decodeURIComponent(parts[i]).split('=');
    			GET[t[0]] = t[1];
    		}
    	})();
    	onload = function(){
    		function $(el){
    			return document.getElementById(el);
    		}
    		var b1 = $('banner-1'), b2 = $('banner-2'), img1 = b1.getElementsByTagName('img')[0], img2 = b2.getElementsByTagName('img')[0];
    		b1.href = b1.href + GET['Email'];
    		img1.src = img1.src + GET['Email'];
    		b2.href = b2.href + GET['Email'];
    		img2.src = img2.src + GET['Email'];
    	};
      </script>
    
    HTML:
    and add an id to both anchors, first anchor id="banner-1", second anchor id="banner-2".

    I'm telling you this for your benefit, it would be much better to do something like this server-side (php). That way even those who dont have js (search engines included) or don't have it enabled would see the correct link.
     
    MMJ, Jan 25, 2009 IP
  7. hcbeggar

    hcbeggar Member

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #7
    MMJ,

    Dont worry, I am upping your fee if this works. Ok, I added the code between the heads, as seen at:
    h**p://www.surveybeggar.com/test2.html?FirstName=Eric&Email=test@test.com

    but I am really a newbie, so please pretend like your speaking to a non coder or a monkey at the zoo. what do you mean "and add an id to both anchors, first anchor id="banner-1", second anchor id="banner-2"."


    also, what do i add in the banner code <a target="_blank" href="http://partners.pantheranetwork.com/z/3945/CD5923/&subid1=> after the &subid= to get it to pull the email address?

    I am really sorry. Usually I can do the basic stuff but this has totally dumbfounded me and perhaps, I am thinking too hard about this but now I cant understand anything
     
    hcbeggar, Jan 25, 2009 IP
  8. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #8
    just add the id attribute to each link (anchor):

    <a target="_blank" href="http://partners.pantheranetwork.com/z/3945/CD5923/?subid1=" id="banner-1"><img src="http://partners.pantheranetwork.com/42/5923/3945/?subid1=" alt="" border="0"></a>
    HTML:
    <a target="_blank" href="http://partners.pantheranetwork.com/z/7442/CD5923/?subid1=" id="banner-2"><img src="http://partners.pantheranetwork.com/42/5923/7442/?subid1=" alt="" border="0"></a>
    HTML:
    and leave the subid1 empty, the javascript function just appends the email right to it.
     
    MMJ, Jan 26, 2009 IP
  9. hcbeggar

    hcbeggar Member

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #9
    ok MMJ

    Thanks....As soon as I read what you typed I felt like a moron...thanks for your patience

    Now I did exactly what you typed an added the id to the first anchor link in banner one. However, after publishing the page, I placed my mouse over the banner it only shows:
    h**p://partners.pantheranetwork.com/z/3945/CD5923/?subid1=

    The email address didnt append to it in the rollover. Any ideas. If you need to, you can check my source code at to see what I did wrong at:

    h**p://www.surveybeggar.com/test2.html?FirstName=tester&Email=chicken@chicken.com
     
    hcbeggar, Jan 26, 2009 IP
  10. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #10
    For some reason when you copied the javascript code all the newlines disappeared. Try copying it again:

    <script type="text/javascript">
    	(function(){
    		var parts = location.href.indexOf('?') >= 0 ? location.href.split('?')[1].split('&') : [];
    		window.GET = [];
    		for (var i = 0, l = parts.length, t; i < l; i++){
    			t = decodeURIComponent(parts[i]).split('=');
    			GET[t[0]] = t[1];
    		}
    	})();
    	onload = function(){
    		function id(el){
    			return document.getElementById(el);
    		}
    		var b1 = id('banner-1'), b2 = id('banner-2'), img1 = b1.getElementsByTagName('img')[0], img2 = b2.getElementsByTagName('img')[0];
    		b1.href = b1.href + GET['Email'];
    		img1.src = img1.src + GET['Email'];
    		b2.href = b2.href + GET['Email'];
    		img2.src = img2.src + GET['Email'];
    	};
    </script>
    Code (markup):
    <a target="_blank" href="http://partners.pantheranetwork.com/z/3945/CD5923/?subid1=" id="banner-1"><img src="http://partners.pantheranetwork.com/42/5923/3945/?subid1=" alt="" border="0"></a>
    <a target="_blank" href="http://partners.pantheranetwork.com/z/7442/CD5923/?subid1=" id="banner-2"><img src="http://partners.pantheranetwork.com/42/5923/7442/?subid1=" alt="" border="0"></a>
    HTML:
     
    MMJ, Jan 26, 2009 IP
  11. hcbeggar

    hcbeggar Member

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #11
    ok I copied it again exactly as I see it posted here and still nada. What am I missing?

    I am getting the info to pass from:
    h**p://www.surveybeggar.com/test.html

    & after i type in Eric for Name and test@test<dot>com for email, they arrive at fine at:
    h**p://www.surveybeggar.com/test2.html?FirstName=Eric&Email=test@test.com

    I put in the exact code you have above in btw the heads and inserted the sub id you gave me but nada....i copied the short cut and you can see the ?subid= and there is nothing following.
    h**p://partners.pantheranetwork.com/z/3945/CD5923/?subid1=
     
    hcbeggar, Jan 26, 2009 IP
  12. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Ah, there is a small hidden problem. In the body tag you have onload="" which stops my script from running. Remove that and it should work.
     
    MMJ, Jan 27, 2009 IP
  13. hcbeggar

    hcbeggar Member

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #13
    Hey MMJ,

    Ok so I hit a snafu....I developed the website through a no brainer program from homestead, and when I discussed taking out that tag, they said that it isnt possible or they wont.

    So I am stuck. I recently saw someone who has developed what I want to do as well. their site is www<dot>CashBackResearch<dot>com. When you fill out the info on their site and click Get Started, it goes to a similar page but your email address are auto filled in the banner as seen when I rolled over it with my mouse.

    I noticed they used java script as well. How did they do it? I perused their source code but cant honestly understand it. Any ideas on how to get me there?
     
    hcbeggar, Jan 29, 2009 IP
  14. NinjaWork

    NinjaWork Guest

    Messages:
    132
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #14
    haha...hey, hcbeggar...you are getting people to do a lot of running around for you for an offer of $10.

    why don't you spend that $10 bucks instead on getting a good webhost?
     
    NinjaWork, Jan 30, 2009 IP
  15. hcbeggar

    hcbeggar Member

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #15
    haha...thanks Ninja....throw a Ninja star at a guy when he is down why dont you. Actually, MMJ has been very helpful thus far, & I planned on upping the ante for him helping if we can get this figured out.

    I am probably going to have to build a seperate "subsite" for this function anyways. So perhaps your right.

    Thanks for checking up on me and my mess.

    ~E
     
    hcbeggar, Jan 30, 2009 IP
  16. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #16
    I'm not doing it solely for the $10 or whatever, if I get cash then thats just a plus.

    All it takes is to remove that attribute but anyways try this:

    
      <script type="text/javascript">
    	(function(){
    		var parts = location.href.indexOf('?') >= 0 ? location.href.split('?')[1].split('&') : [];
    		window.GET = [];
    		for (var i = 0, l = parts.length, t; i < l; i++){
    			t = decodeURIComponent(parts[i]).split('=');
    			GET[t[0]] = t[1];
    		}
    	})();
    	var ie = window.attachEvent;
    	window[ie ? "attachEvent" : "addEventListener"]((ie ? "on" : '') + "load", function(){
    		function $(el){
    			return document.getElementById(el);
    		}
    		var b1 = $('banner-1'), b2 = $('banner-2'), img1 = b1.getElementsByTagName('img')[0], img2 = b2.getElementsByTagName('img')[0];
    		b1.href = b1.href + GET['Email'];
    		img1.src = img1.src + GET['Email'];
    		b2.href = b2.href + GET['Email'];
    		img2.src = img2.src + GET['Email'];
    	}, false);
      </script>
    Code (markup):
    I tried it and it worked.
     
    MMJ, Jan 30, 2009 IP
  17. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #17
    to be honest, i just don't buy this - why the xxxx can't a body onload= be removed? if its constraints of WYSIWYG 'design' software, then by god--view source and edit it yourself, don't call some xxxxwits on some helpdesk to be told that you can't...

    that aside, kudos to MMJ for finding a way :D
     
    dimitar christoff, Jan 30, 2009 IP
  18. hcbeggar

    hcbeggar Member

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #18
    SUCCESS!!!

    Thank You MMJ for all your help, I will try to Private message you to obtain your paypal or such.
     
    hcbeggar, Jan 30, 2009 IP