No announcement yet.

HTML Parameter passing

  • Filter
  • Time
  • Show
Clear All
new posts

  • HTML Parameter passing


    Is there a way to pass a string from one HTML file to another.

    I would like to have one HTML file, i.e. picture.html in which I would then pass the name or location of the image I want to have displayed.

    Can this be done?


  • #2
    Hi Milojko, and welcome to HTMLForums!
    You could use a query string plus a server side script or JavaScript to pass data... or alternatively cookies, but I'd recommend a query string.
    You can have this link on page 1:
    <a href="page2.html?firstname=John&lastname=Doe">View page 2</a>
    And then this code for page 2:
    <title>Page 2</title>
    <script type="text/javascript">
    var query = location.href.substring((location.href.indexOf('?')+1), location.href.length);
    if(location.href.indexOf('?') < 0) query = '';
    querysplit = query.split('&');
    query = new Array();
    for(var i = 0; i < querysplit.length; i++){
        var namevalue = querysplit[i].split('=');
        namevalue[1] = namevalue[1].replace(/\+/g, ' ');
        query[namevalue[0]] = unescape(namevalue[1]);
    window.onload = function(){
        // Do stuff with query string data here.
        document.getElementById('firstname').innerHTML = query['firstname'];
        document.getElementById('lastname').innerHTML = query['lastname'];
    <h1>Page 2</h1>
    <p>Your name is <span id="firstname"></span> <span id="lastname"></span></p>
    You can change the command at the location of "do stuff with query string data here", if you get further questions, just ask


    • #3


      I'll say this: YOU THE MAN!!!

      This is all I actually needed but I wouldnt do it without your help:

      		<SCRIPT TYPE="text/javascript">
      			function getPicture()
      				var picture = location.href.substring((location.href.indexOf('pic=')+4), location.href.length);
      				return picture;
      		<SCRIPT TYPE="text/javascript">
      			document.write("<IMG SRC='"+getPicture()+"'>")


      • #4
        Passing an affiliate ID as a parameter

        I read this thread and the solution and am wondering if you could please show me how to pass a simple string from one html page to another using the javascript function, in the same way you did it in this example. I would like to be able to pass an affiliate ID which is just a long string of characters. Then I want to receive it in the receiving html page and pass it forward to the next html page for as long as the user browses the pages in the site.
        How would I do this?


        • #5
          You bumped a thread which has been dead for more than seven years, so don't wait for a response from the previous posters in this topic.

          You should really (seriously, I'm not messing around) store the affiliate ID in a session variable on the server. That way you're not relying on JavaScript and you don't have to add a bunch of invasive code to every single page. Tell us which server-side language is offered by your web host (PHP, Perl, Python,, etc.) and we can help you further.

          If for some reason you absolutely must do this with JavaScript on the client side (not recommended), then just store the affiliate ID value in localStorage or a cookie. You should never have to programmatically transfer the value through links.

          It's worth noting that the only solution which is 100% reliable is storing the value in a session variable. Everything else depends on whether the visitor has JavaScript, cookies, and/or localStorage enabled in his browser.