473,511 Members | 17,164 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple Parameter Processing

Good Morning,

I am trying to write a simple function that would grab the "errorId"
parameter and then display a message when the page loads. I basically
have a login page (login.asp) that if the login fails the user is
directed page to the login page with an errorId parameter (login.asp?
errorId=1).

I wrote the javascript below to grab the paramater and then retuen a
message (I borrowed the gup function from an example, and wrote the
getMessage)

Now, my problem is that I am not sure how to get the message returned
by getMessage displayed on the screen. I think that adding the
function to window.onload would call it when the page loads, but I
don't know how to get the text written out to the browser window.

Thanks in advance for any help!
Doug

function gup( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null ) return "";
else return results[1];
}

function getMessage( )
{
var error = gup("errorId");
if (error == "") return "";
else return "Email address and password combination not found.";
}

Oct 6 '07 #1
1 1555
DougJrs wrote:
I am trying to write a simple function that would grab the "errorId"
parameter and then display a message when the page loads. I basically
have a login page (login.asp) that if the login fails the user is
directed page to the login page with an errorId parameter (login.asp?
errorId=1).

I wrote the javascript below to grab the paramater and then retuen a
message (I borrowed the gup function from an example, and wrote the
getMessage)
But, while that might have been a good training for a general client-side
solution for parsing the query string (which is seldom necessary anyway),
it is far too complicated in your case.
function gup( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null ) return "";
else return results[1];
}
That code strikes me as being unnecessarily complicated, and error-prone.

For example, there will not be an unescaped "[" or "]" character in the
query part of a Valid URI (see RFC3986, 2.2.) However, if we assume that
the method can be passed a string containing such characters, precautions
must be taken for other reserved characters, too.

function getFirstQueryParam(p)
{
var q = window.location.search;
if (typeof q == "string")
{
var m = q.match(
new RegExp("[\\?&]?" + encodeURIComponent(p) + "=([^&#;]*)"));
if (m) return decodeURIComponent(m[1]);
}

return false;
}

var error = getFirstQueryParam("errorId");

See also http://PointedEars.de/scripts/search.js
Now, my problem is that I am not sure how to get the message returned
by getMessage displayed on the screen. [...]
Instead of
function getMessage( )
{
var error = gup("errorId");
if (error == "") return "";
else return "Email address and password combination not found.";
}
you simply write something along (assuming JScript or JScript.NET server-side):

<%
if (condition)
{
%>
Email address and password combination not found.
<%
}
%>

You may include that anywhere in your markup, even in generated client-side
script code.

That is, in the case of an error you do not first serve much the same
resource and then retrieve the error code from the query part, but you
serve a different resource in the first place. Which can remove the
necessity for using client-side scripting there.
PointedEars
Oct 6 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
36552
by: JT | last post by:
how can i declare a function that will accept an optional parameter? something like: function newFunc(strValue1, strValue2) --where strValue2 is optional. thanks much.
10
1899
by: Adrian | last post by:
Hi I want to write a form that when a user presses submit it carries out the submit action and then closes the browser or redirects to another page. The form CGI I'm using, Demon's does not...
3
5464
by: Brett | last post by:
I have several classes that create arrays of data and have certain properties. Call them A thru D classes, which means there are four. I can call certain methods in each class and get back an...
1
3615
by: Joe Monnin | last post by:
I have a web service that takes an XmlDocument as a parameter, performs some processing on it, and saves it to a database. The web service signature looks similar to this: public void...
0
7245
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7427
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5069
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3214
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1577
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.