Jump to content

Need help with javascript code generator


T3KNOSIS

Recommended Posts

Hi, i am trying to create a script generator where you enter your gamertag and when you hit enter it displays an html code in the box below. I want the html code that is generated to include an href= and an img src with the name you entered at the end of each. (ie.<a href="http://us.playstation.com/playstation/psn/visit/profiles/NAME"><img src="http://fp.profiles.us.playstation.com/playstation/psn/pid/NAME.png" width="230" height="155" border="0" /></a>) What i want to do is when you enter your gamertag in the above box and hit enter, it gets put into the code above where it says NAMEThis is what i have come up with, however when you enter your name, it only enters your name in the first part of the HTML code.<p>This gamercard is directly linked to Playstation.com meaning it is instantly updated with your latest achievements. To get the HTML code for your own PSN ID Card, simply enter your PSN ID in the box below:<script type="text/javascript">function UpdateGcardCode() {var code1 = '<a href="http://us.playstation.com/playstation/psn/visit/profiles/';var code2 = '"><img src="http://fp.profiles.us.playstation.com/playstation/psn/pid/';var code3 = '.png" width="230" height="155" border="0" /></a>';document.getElementById("gcardcode").value=code1+document.getElementById("gtagname").value + code2 + code3;}</script><br /><input type="text" id="gtagname" onChange="UpdateGcardCode()"/><br/>Copy and paste the HTML code from the box below into your Profile or Signature:<br /><textarea id="gcardcode" cols="50" rows="4" onfocus="this.select();">Please enter your PSN ID (nickname) in the box above, and then hit enter to generate your code.</textarea><br />As you can see with this script, the name you enter in the above box only gets placed in code1 of the script. I would like the name you type to be entered into both code1 and code2 when you hit enter to generate the html code. PLEASE HELP!

Link to comment
Share on other sites

You're only adding it once:document.getElementById("gcardcode").value=code1+document.getElementById("gtagname").value + code2 + code3;You need to add it the second time too:document.getElementById("gcardcode").value=code1+document.getElementById("gtagname").value + code2 + document.getElementById("gtagname").value + code3;A simpler way would be to just set the PSN ID to a variable and just assign the raw HTML to your output location using the PSN ID variable where appropriate. Something like:var psn_id = document.getElementById("gtagname").value;document.getElementById("gcardcode").value = '<a href="http://us.playstation.com/playstation/psn/visit/profiles/'+psn_id+'"><img src="http://fp.profiles.us.playstation.com/playstation/psn/pid/'+psn_id+'.png" width="230" height="155" border="0" /></a>';

Link to comment
Share on other sites

Thank you sooo much, you solved my problem!!! I appreciate your help. This code is a general script i am using for all card generators for my site and i wasnt sure how to add both codes into the line: document.getElementById("gcardcode").value = THANKS again!!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...