VB icon

Read Query String on Client Side Using VBScript

Submitted on: 1/5/2015 8:27:00 PM
By: Marcio Coelho (from psc cd)  
Level: Intermediate
User Rating: By 5 Users
Compatibility: VbScript (browser/client side)
Views: 4538
     This function reads all query string dynamically. Read for copying, pasting and testing
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
' Name: Read Query String on Client Side Using VBScript
' Description:This function reads all query string dynamically.
Read for copying, pasting and testing
' By: Marcio Coelho (from psc cd)

<%@ Language=VBScript %>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<Form name="stringsample" id="stringsample"action="clientquerystring.asp" method=GET id=form1 name=form1>
<P> </P>
<INPUT type="text" id=text1 name=text1><BR>
<INPUT type="text" id=text2 name=text2><BR>
<INPUT type="text" id=text3 name=text3><BR>
<INPUT type="submit" value="Submit" id=submit1 name=submit1>
private queryId()
private queryvalue()
Private maxBound
Sub Window_OnLoad()
		call ClientQueryString()
		REDIM Preserve queryid(maxBound)
		REDIM Preserve queryvalue(maxBound)	
		for i = 0 TO maxBound
					msgbox queryid(i) & " value is " & queryvalue(i)
					Select Case i
							Case 0
									document.stringsample.text1.value = queryvalue(i)		
							Case 1
									document.stringsample.text2.value = queryvalue(i)	
							Case 2
									document.stringsample.text3.value = queryvalue(i)	
					End Select	
					If len(queryvalue(i)) = 0 Then
						msgbox "there is no value for " & queryid(i)
				end If 
end sub
Function ClientQueryString()
	Dim urlString, bPos, ePos, firstPartofPair, secondPartofPair, exitDo, i, h, take
	Dim countquery
	exitDo = False
	countquery = 0
	urlString = document.url 'retrieve complete url
	bPos = Instr(1, urlString, "?", 1) + 1 'question mark (?) will determine if there is any query
	If bPos > 1 Then
							' We have at least one valid value pair in the QueryString
							Do Until exitDo
												ePos = Instr(bPos, urlString, "=", 1) 'get the position that separate variable of query name and the value of the query string
												firstPartofPair = Mid(urlString, bPos, ePos - bPos) 'retrieve the variable name
												bPos = ePos + 1 'move for the next position after the =
												If Instr(bPos, urlString, "&", 1) > 0 Then 
													ePos = Instr(bPos, urlString, "&", 1)
													secondPartofPair = Mid(urlString, bPos, ePos - bPos) ' retrieve the variable value
													' End of QueryString has been reached
													ePos = Len(urlString)
													take = ePos - BPos
													If take = 0 Then take = 1
													if take <> -1 Then 	secondPartofPair = Mid(urlString, bPos, take)
													exitDo = True
												End If
											REDIM Preserve queryid(countquery) 
												queryid(countquery) = firstPartofPair
												REDIMPreserve queryvalue(countquery) 
												queryvalue(countquery) 	= secondPartofPair
												countquery = countquery + 1 'increment the number of query string passed
												bPos = ePos + 1
	End If
	maxBound = countquery - 1
End Function

Other 3 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)

To post feedback, first please login.