Optional Arguments in JScript

If you truly want to be able to pass or not pass arguments arbitrarily in Active Server Pages you can revert to JScript, which allows you to pass as few or as many arguments as you like:

<%@language=JScript%>
<%
// Don't declare any arguments in the function declaration:
function SomeArgs() {
var strReturn = new String('');

// Instead, use the intrinsic arguments object to retrieve arguments.
// This loops through the arguments object appending the value of each
// to the result:

for (i=0; i<arguments.length; i++) {
strReturn += arguments[i];
}
return(strReturn);
}

// Pass whatever arguments you like:
Response.Write(SomeArgs('one' , 'two', 'three'));
Response.Write('<br>');
Response.Write(SomeArgs(1, 2, 3, 4, 5, 6, 7, 8));

// Displays this:
// onetwothree
// 12345678
%>

You might also like...

Comments

James Crowley James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audience ...

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The generation of random numbers is too important to be left to chance.” - Robert R. Coveyou