How to create a variable in HTML?

Discussion in 'HTML & Website Design' started by netgo, Apr 18, 2010.

  1. #1
    I have a variable within javascript code that I have on my webpage

    I want to take this variable and use it in the HTML code of the same page

    How can I do this?

    I want to create a sub id with this dynamic variable as a text string
     
    netgo, Apr 18, 2010 IP
  2. krsix

    krsix Peon

    Messages:
    435
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    no clue what you're trying to do, but HTML doesn't have variables.

    you can use javascript to spit out variables (ie innerHTML = '<div id="'+varname+'">';)
     
    krsix, Apr 18, 2010 IP
  3. Piggy

    Piggy Active Member

    Messages:
    574
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    70
    #3
    Yeah, what do you mean by variable in html? Are you trying to call an Id or class in the HTML script, but from a css file? As in, you have the same variable set in your inline javascript, as well as in your external CSS file. You're wanting to call on the CSS variable in HTML, without interrupting the inline javascript?
     
    Piggy, Apr 18, 2010 IP
  4. netgo

    netgo Active Member

    Messages:
    279
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #4
    Have a variable within the javascript code , that i want to use in the html code.

    Basically I want this variable to be a part of an affiliate link. I would like the subid part of the link to be that variable.

    It isn't in my css, I have just opened a new page in wordpress and I've put both the javascript and html there.
     
    netgo, Apr 19, 2010 IP
  5. Piggy

    Piggy Active Member

    Messages:
    574
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    70
    #5
    Ok, so you're saying:
    <a href='http://www.affiliate.com/'>VARIABLE</a>
    Code (markup):
    What you're calling a variable isn't really a variable... It's just text lol You shouldn't have any problems putting the same thing in both spots since the link isn't a variable.

    But if that's not what you're meaning, then can you provide the code or an example of what you're talking about?
     
    Piggy, Apr 19, 2010 IP
  6. netgo

    netgo Active Member

    Messages:
    279
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #6
    No that's not what I meant. In your example, what I want is <a href="http://www.affiliate.com/subid=VARIABLE">

    I don't have a code. This is what I am asking for.

    The example is as follows: I ask the user to submit an email. Once they click submit, they get redirected to another url,
    this url contains their email in the following manner: http://mysite.com/mypage/?email=test@ds.con
    (in this example the email submitted was )

    Now I want to take that part - test%40ds.con and have it placed on my page several times.

    Every time I have a url with a subid, I want the subid to equal test%40ds.con

    So when I later look at the subid report, I will be able to identify from what email address each line in the report comes from
     
    netgo, Apr 19, 2010 IP
  7. krsix

    krsix Peon

    Messages:
    435
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #7
    PHP: $_GET [sanitize this crap]
    JS: window.location.search.substring(1);
     
    krsix, Apr 19, 2010 IP
  8. netgo

    netgo Active Member

    Messages:
    279
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #8
    KRSIX - Not sure what to do with what you've written.

    I am using wordpress so I only know how to write html. I have added a bit of javascript as I described above, but other than that I really don't know how to program.

    If anyone can please refer me to a source that will explain this or simply let me know how all the other sites do it -

    take a text string in javascript, save it in some way and add it to my html code.
     
    netgo, Apr 20, 2010 IP
  9. javier.garcia.esteban

    javier.garcia.esteban Well-Known Member

    Messages:
    66
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    118
    #9
    As krsix said, either you do it server-side (ie: PHP) or via javascript, but either way you need some programming skills.

    WordPress is PHP-based. Wherever you want to use that "variable" you just have to write <?php echo $_GET["email"]; ?>, ie:

    <a href="http://www.affiliate.com/subid=<?php echo $_GET["email"]; ?>">
     
    javier.garcia.esteban, Apr 20, 2010 IP
  10. Piggy

    Piggy Active Member

    Messages:
    574
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    70
    #10
    Yeah, this isn't possible with just HTML. You're going to have to use $GET["email"] via php to impliment what you're needing. I'm not a php programmer, but there's hundreds of them around. I'd recommend making a post in Buy/Sale/Trade asking somebody to make you a simple code.
     
    Piggy, Apr 20, 2010 IP
  11. krsix

    krsix Peon

    Messages:
    435
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Please don't directly $_GET['email'], that's just begging to be XSS'd.

    It _is_ possible to do it with JS, using window.location.search.substring.
     
    krsix, Apr 20, 2010 IP
  12. jezzz

    jezzz Notable Member

    Messages:
    4,884
    Likes Received:
    190
    Best Answers:
    0
    Trophy Points:
    200
    #12
    HTML doesn't support variables however you can try PHP it supports variable in most comprehensive way!
     
    jezzz, Apr 20, 2010 IP
  13. netgo

    netgo Active Member

    Messages:
    279
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #13
    I was able to do it with $_GET['email'] - KRSIX - How do I sanitize it to prevent security problems?
     
    netgo, Apr 21, 2010 IP
  14. javier.garcia.esteban

    javier.garcia.esteban Well-Known Member

    Messages:
    66
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    118
    #14
    The easiest way you can do it is using htmlentities($_GET['email']), you'll prevent code injection with that.
     
    javier.garcia.esteban, Apr 21, 2010 IP
  15. netgo

    netgo Active Member

    Messages:
    279
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #15
    how can I carry the url with the user's email across to a second page? is there a way to make it so that when the user clicks "continue" and moves to the next page this url will also have the previously submitted email?
     
    netgo, May 3, 2010 IP
  16. ericpond

    ericpond Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    thanks for diving the information about it because i also don't know about it.
     
    ericpond, May 3, 2010 IP
  17. netgo

    netgo Active Member

    Messages:
    279
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #17
    Any help or sources where I can read this will be much appreciated
     
    netgo, May 3, 2010 IP