0

I am passing a querystring from my previous page to this page and then i want to pass it to the next page, but it isn't working.

<script type="text/javascript">
           function qs(search_for) {
        var query = window.location.search.substring(1);
        var parms = query.split('&');
        for (var i=0; i<parms.length; i++) {
            var pos = parms[i].indexOf('=');
            if (pos > 0  && search_for == parms[i].substring(0,pos)) {
                return parms[i].substring(pos+1);;
            }
        }
        return "";
    }
    </script>

here is the link

<a href="http://www.TEST.com/TEST/TEST/TEST.aspx?comp=" & <script type="text/javascript"> document.write(qs("comp")); </script> & "name=test" >CLICK HERE </a></font></b></p>
4
  • What the heck is that syntax in the <a> tag? What are those ampersands supposed to do, or mean? Maybe that's some kind of weird ASP thing, but I can't imagine any way that that's going to work. Commented Jan 20, 2011 at 19:13
  • it doesnt : / all i want is to use pass my querystring from the previous page to the next Commented Jan 20, 2011 at 19:14
  • Ah, OK :-) Well that's good then and I can stop googling for that syntax!! Commented Jan 20, 2011 at 19:34
  • I think maybe if you'd describe more of the problem, people might be able to help out more. It's not exactly clear what your pages look like, how the forms interact, etc etc. Commented Jan 20, 2011 at 19:35

3 Answers 3

1

Probably easier, more flexible, and more maintainable to just stick it in a hidden field and then retrieve it with a simple document.getElementById().

Sign up to request clarification or add additional context in comments.

6 Comments

how can i place it in a hidden field
@MyHeadHurts, in your markup add a form (if you don't already have one), with <input type="hidden" value="" name="foo" id="foo"> and using ASP add the relevant variables for each value.
@MyHeadHurts, if you provide a little more detail it would make it easier to help. "didn't work" is about as helpful as me going to the doctor complaining about my health and expecting medicine. i dont know many doctors who prescribe medicine without checking the symptoms...
sorry i am not using asp can i still hide the variable in an asp form
i just want to use the querystring that i passed to an html page in a link to another page,
|
0
  • Page 1 Creates URL querystring

  • Page 2 add this to your second page
    <asp:hiddenfield runat="server" id="hdncomp" value=""/> <asp:hiddenfield runat="server" id="hdnname" value=""/>

    Now, in your Page 2 Load event run the following code.

    Me.hdncomp = Request.QueryString("comp")
    Me.hdnname = Request.QueryString("name")
    
  • Finally, when you go to Page 3 Use the values from hdncomp and hdnname as your parameter values. For example:

Response.Redirect("page3.aspx?comp=" & hdncomp & "&name=" & hdnname)

Untested code

Comments

0

well, your syntax is very wrong. you cannot write a new element before closing the first elements tag : <element <element2 /> /> . here's a function that you can use :

function createLink(address,param,text){
   address += ((address.indexOf('?') == -1) ? "?" : "&") 
      + param 
      + "="
      + qs(param);
    document.write(''+text+'');
}
and then, when you want to insert the desired link by inserting a script tag calling the "createLink" function with the desired parameters :
<script type="text/javascript">
createLink("http://www.TEST.com/TEST/TEST/TEST.aspx?name=test","comp","CLICK HERE");
<script/>

Hope this helps!

p.s. : you should probably use only one semicolon and not two at a time.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.