first post! hello all. :)
i'm in the process of converting some vbscript into jscript at work, and not being an expert when it comes to any sort of javascript (or c syntax generally) i am now stuck. specifically with the 'switch' statement.
the application is a server-side api that returns xml based on arguments sent to it in the querystring of its url.
e.g. /server_api.asp?action=getObjectByID&id=53
in vbscript i was grabbing all the arguments from the querystring and putting them into a scripting dictionary object called "qsDetail". then i was calling each like so... qsDetail("id") ...or whatever. iterating through each key/value pair was easy as you just use 'for...each'. obviously no such thing in jscript so i went with an enumerator object, iterating through each item and passing each pair to an associative array, like so:
var qsDetail = [];
var e = new Enumerator(Request.QueryString);
for (;!e.atEnd();e.moveNext()) {
var x = e.item();
qsDetail[x] = Request.QueryString(x);
}
so far so good. however, in the following function the 'switch' statement simply refuses to work. putting Response.write lines in to debug it, it emerges that the value "category" is indeed being passed through to the switch statement (in the example of the url above). but it just bails. if you add "default: <something>" then it runs that line instead.
function getObjectByID() {
var strSQL = "SELECT id, type, name, description FROM object WHERE id =" + qsDetail["id"];
var oRs = oConn.Execute(strSQL);
if (oRs.EOF) {
emptyXML();
} else {
outputXML = '<?xml version="1.0" ?>\n';
// Loop for safety reasons, despite ID being unique
while (!oRs.EOF) {
switch (oRs("type")) {
case "category": outputXML += processCategory(oRs("id"));
case "skill": outputXML += processSkill(oRS("id"));
}
oRs.MoveNext;
}
}
}
but if you replace the 'switch' statement with two 'if' statements then everything runs smoothly and it correctly goes with 'category, and the rest of the code runs fine.
if (oRs("type") == "category") {
outputXML += processCategory(oRs("id"));
}
if (oRs("type") == "skill") {
outputXML += processSkill(oRs("id"));
}
which is almost all well and good, except for ... why?!
i simply cannot see what is wrong with that 'switch' statement. in itself there appears to be nothing wrong, so i assume it has to be something in the context of the rest of the code. there are no problems relating to the DB or variables, as everything runs fine once you make the changes referred to above.
any jscript experts out there able to shed some light on this?
thanks in advance.