0

I have two HTML which is (simply name is as one.html & two.html) for the two.html, i have a query string, when the url show two.html?var=1 it will show images that i set at the jquery. two.html sample (not sure why not working at jsfiddle, when the code in local it working fine.)

HTML

 <div class="itemabc"><img src="http://s7.postimg.org/7zbcr6ytz/photo1.jpg id="item1" /></div>

Jquery

      $(document).ready(function(){
    var target = getParameterByName('var');
    if (target == 1) {
      $("#item1").attr("src","http://s7.postimg.org/7zbcr6ytz/photo1.jpg");
    }
    else if (target == 2){
        $("#item1").attr("src","http://s22.postimg.org/v6gqap331/photo2.jpg");
    }

    else if (target == 3){
        $("#item1").attr("src","http://s22.postimg.org/anqfjdejh/photo3.jpg");
    }

    else if (target == 4){
        $("#item1").attr("src","http://s22.postimg.org/75efmzdnh/photo4.jpg");
    }


    else if (target == 5){
        $("#item1").attr("src","http://s22.postimg.org/9pa2h317h/photo5.jpg");
    }

    else {
        $("#item1").attr("src","http://s22.postimg.org/mfeau695p/photo6.jpg");
    }

  });
  function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
    results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
  }

And then, now i don't know how to post the variable to two.html, reason why i doing this, because i'll have few item to be select at one.html, then after send, two.html will display what i select previously.

lala90
  • 151
  • 1
  • 3
  • 11

1 Answers1

1

you can get parameter from url in javascript

please review this link

Community
  • 1
  • 1
caoglish
  • 1,343
  • 3
  • 19
  • 29