Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Redirect URL keeps adding the same string

Posted on 2015-01-28
6
Medium Priority
?
87 Views
Last Modified: 2015-01-28
Here is the code:

    Dim MM_editRedirectUrl
    MM_editRedirectUrl =  Request.ServerVariables("URL") & "?"

    If (Request.QueryString <> "") Then
      If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then
        MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
      Else
        MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString & "&index=" & (CStr(Int(Request.QueryString("index"))) + RecordExam_numRows)
      End If
    End If
    Response.Redirect(MM_editRedirectUrl)

The first time, it works, and I get this:

http://www.libertylabs.com/tana11/exama43w.asp?&EmpID=29&TestID=44&index=1

But the second time, I get this:

http://www.libertylabs.com/tana11/exama43w.asp?&&EmpID=29&TestID=44&index=1&index=2

When I want to get this:

http://www.libertylabs.com/tana11/exama43w.asp?&EmpID=29&TestID=44&index=2
0
Comment
Question by:MzLiberty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 18

Expert Comment

by:nap0leon
ID: 40575859
Firstly, this should be tagged with and placed in a topic for "Classic ASP" instead of "JavaScript".

Secondly, in what situation would you be running the code a second time?  The code does a redirect, it ought to run once and redirect to the new page.  Perhaps you are meaning that the code is running again after the page has redirected and it should not?

As for the issues in the code provided...
Your first "If" is checking to see if "Request.QieryString" is not empty.
Your second "If" is checking to see if the path you constructed does not contain a "?" in it... but you added a "?" to it when you created the variable, so it will always have one.

On the off-chance that you were intending to check to see if "index=" is in the QueryString (with the intention of adding it if it is not), then something like this would work:
<%
Dim RecordExam_numRows
RecordExam_numRows = 3

Dim MM_editRedirectUrl
MM_editRedirectUrl =  Request.ServerVariables("URL") & "?"
%>

Path w/ ?: <%=MM_editRedirectUrl%><br/>

<%
If (Request.QueryString <> "") Then
	If (InStr(1, Request.QueryString, "index=", vbTextCompare) = 0) Then
		MM_editRedirectUrl = MM_editRedirectUrl & Request.QueryString & "&index=" & (CStr(Int(Request.QueryString("index"))) + RecordExam_numRows)
		'Response.Redirect(MM_editRedirectUrl)
	Else
		MM_editRedirectUrl = MM_editRedirectUrl & Request.QueryString
	End If
End If
%>

Finish: <%=MM_editRedirectUrl%><br/>

Open in new window

0
 

Author Comment

by:MzLiberty
ID: 40575904
That works the first time, but only the first time...it gives me index #1 but I need it to go to index #2 the second time. It just keeps giving me index #1. The code I had gave me the second index, but kept the first one in there. I don't know which part of that code is causing it to keep the first index and then add the second...I'm just trying to piece this together as I obviously don't know what I'm doing :) Thanks!
0
 
LVL 18

Expert Comment

by:nap0leon
ID: 40575912
If you are stuck at "1" then it is because you do not have a value for "RecordExam_numRows"

In your original code, you are adding "index=something" to the QueryString which already contains "index=something", so now it is in there twice.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:MzLiberty
ID: 40575942
Yes, it is in there twice, that's the problem...but the second time, it does give me the correct number (2, then 3 and so on) but how do I make it only give me the 2 and not the 1 again?
0
 
LVL 18

Accepted Solution

by:
nap0leon earned 2000 total points
ID: 40576229
Found a function on stack overflow that works nicely.
In this example, if index is not in the QueryString, it adds it as "index=3".
If index is in the URL, e.g., index=5, it adds 3 so it results in index=8

<%
Dim RecordExam_numRows
RecordExam_numRows = 3

Dim MM_editRedirectUrl
MM_editRedirectUrl =  Request.ServerVariables("URL") & "?"
%>

Path w/ ?: <%=MM_editRedirectUrl%><br/>

<%
Function updateQueryStringParam(key, value)
	Dim qs, x
	For Each x In Request.QueryString
		qs = qs & x & "="

		If x = key Then
			qs = qs & value & "&"
		Else
			qs = qs & Request.QueryString(x) & "&"
		End If
	Next

	If Len(qs) > 0 Then
		If Right(qs, 1) = "&" Then
			qs = Left(qs, Len(qs)-1)
		End If
	End If

	updateQueryStringParam = qs
End Function

If (Request.QueryString <> "") Then
	If (InStr(1, Request.QueryString, "index=", vbTextCompare) = 0) Then
		MM_editRedirectUrl = MM_editRedirectUrl & Request.QueryString & "&index=" & (CStr(Int(Request.QueryString("index"))) + RecordExam_numRows)
		'Response.Redirect(MM_editRedirectUrl)
	Else
		'increment index
		MM_editRedirectUrl = MM_editRedirectUrl & updateQueryStringParam("index", Int(Request.QueryString("index")) + RecordExam_numRows)
	End If
End If
%>

Finish: <%=MM_editRedirectUrl%><br/>

Open in new window

0
 

Author Comment

by:MzLiberty
ID: 40576437
Thanks for your help. At least I'm getting closer to making it work.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question