If ElseIf within another If ElseIf in ASP

Hi, i've this problem here.. Which i suspect is about IF-Else Statement within another IF-Else Statement in ASP.

Basically when the current page needs to run Chapter1.asp, it couldn't work.

Chapter1.asp(below page) is being link by this current page when the 'init()' function is activated by pressing a button (Start button, next button), the following few lines of codes is shown here:

Start button

function init()
{
objXmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
objXmlDOM = new ActiveXObject("Microsoft.XMLDOM");
objXmlHTTP.open("POST","Chapter1.asp?Action=Start",false);
objXmlHTTP.send("");
.....
}

Next button

function getNextQ()
{
//update the user's answers list
checkAnswer();

//increment the question no - i.e. to next Question
count++;

url = "Chapter1.asp?Action=NextQ&QNo=" + aQuest[count];
objXmlHTTP.open("POST", url ,false);
objXmlHTTP.send("");
objXmlDOM.loadXML(objXmlHTTP.ResponseText);


//parse the response content fetched from the server
//and display the question
parseQ();
}

- So there is a main IF-ELSEIF statement in Chapter1.asp to check which button was pressed and do something.

But i had added 2 new IF-ELSEIF (1st in brown - to check the session and use the correct XML file..) (2nd in brown - to set different questions for different session pass over, but it is only activated only within the 'Start' in red...)


-----------------------------------------------------
Chapter1.asp
<%

varlevel = Session("level")
varfail = Session("varfail")

set obj = server.createobject("Microsoft.XMLDOM")
obj.async = false

if varlevel = 1 then
obj.load(Server.MapPath("C1L1.xml"))
elseif varlevel = 2
obj.load(Server.MapPath("C1L2.xml"))
elseif varlevel = 3
obj.load(Server.MapPath("C1L3.xml"))
end if


Response.expires = 0

if trim(request("Action")) = "Start" then

Dim TotalQ

TotalQ = obj.selectNodes("data/question").length

Dim aQuest(),temp,isExist,strQ
ReDim aQuest(0) 'to store the question ids

'This below algorithm is for checking whether which tries is he taking now and read out the question.

elseif varfail = 0
strQ = "1,2"
elseif varfail = 1
strQ = "3,4"
elseif varfail = 2
strQ = "5,6"​
end if


response.write strQ


'all further requests - after the first request

elseif trim(request("Action")) = "NextQ" then

temp = "data/question[@id=" & trim(request("QNo")) & "]"

set Node = obj.selectSingleNode(temp)

strXML = "<data>"
strXML = strXML & "<qtext>"
strXML = strXML & Node.selectSingleNode("qtext").text

......

end if
%>

Hope it's not confusing for anyone of you out there reading, and if you have a solution or like to find out more, do reply me .. Thanks alot!
 
I think your elseif varfail = 0 should be an IF. Something like this:

Code:
If trim(request("Action")) = "Start" Then
  If varfail = 0 Then
    ...
  ElseIf varfail = 1
    ...
  Elseif varfail = 2
    ...
  End If

Else If trim(request("Action")) = "NextQ" Then
  ...
End If

Select Case would be a more tidy way to go. I think you can do select case in ASP / VBScript.

Code:
SELECT CASE trim(request("Action"))

CASE "Start"

  SELECT CASE varfail
  CASE 0
    ...
  CASE 1
    ...
  CASE 2
    ...
  END SELECT

CASE "NextQ"
  ...
END SELECT
 
Hi Tetranz,

The page still has no response even after i tried both your method.

Basically if i took out the brown codes, the whole page could work.

The brown codes was my own add-on extension so as to do more of 'intelligence' checking.. So therefore could only use If-else, or Select Case method...

Both the varfail and and varlevel were store in session from previous page and request in this Chapter1.asp page..

But i suspect it has something to do with the session, because on the main page where my buttons were, there are quite a few session retrieve and setting, therefore it may be incidentally 'abandon'..
 
The ELSEIFs in the brown part are missing their 'Then' keywords.
IF and ELSEIF both require a THEN, it's only ELSE that doesn't.
 
Back
Top