• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 434
  • Last Modified:

Passing Data from Javascript to ASP using hidden form post

Hi, Experts -
We test new job applicants on shared PCs in a testing room.  We run testing software that uses a Javascript module to capture score info.  We have modified this Javascript module so that it passes the score info to an ASP program (using method=post and hidden form fields).  On the receiving end, the ASP program uses a Request.Form to retrieve the data passed to it - and then loads it into a database table.  The data being passed should consist of five elements for each of the 25 questions on a quiz - a total of 125 items.
Most of the time, the program works without incident.  But every once in a while, the ASP program will abort with a "subscript out of range" error because the code assumes that there will be five elements for each question - and sometimes the Javascript module does not pass all 25 questions over to the ASP program (confirmed this with onscreen displays).
So, I have a two-part question:
Part 1.  Why would the Javascript pgm not pass all of the data over to the ASP program - on occasion - and what can we do to minimize this occurrence (like restart the PC to flush the IE cache)?
Part 2.  How can I modify the ASP code to account for the possibility that not all the data was passed (see my snippet from the ASP program below) - and continue to update the database with whatever was passed?
for i = 0 to (Ubound(LineDetails) - 1) Step 5
			vstrObjectiveID 	= LineDetails(i)
			response.write("D E B U G   1) vstrObjectiveID = " & vstrObjectiveID & "<br>")
			vstrInteractionType = LineDetails(i+1)
			vstrResponse 		= LineDetails(i+2)
			vstrResult 			= LineDetails(i+3)
			vstrLatency 		= LineDetails(i+4)

			' Create a new record in recordset

			if vstrLastName <> "" 		then rsDtl("dtl_LastName")= vstrLastName 			else rsDtl("dtl_LastName")=" "

Open in new window

  • 4
  • 2
1 Solution
Eduardo GoicovichIT ConsultantCommented:
I can see all the code. Can you repost?
OGSanAuthor Commented:
Hi, belfegor - I don't mind reposting all the code, except that I don't think it adds any insight to the problem.  If you see the snippet of code above, the problem is that the for/next loop steps by 5 in anticipation of the five elements per question it ASSUMES is being passed.  When there aren't five elements passed, the code bombs out where it references an "i+X" value because...there's nothing there.  I need a way to improve those hardcoded subscript values that are assuming five elements will be passed - but I'm not sure how to do that.
Hope that makes sense, and helps to clarify the Part 2 issue.
1) can you post the JavaScript that gathers the data and sends it to the server
2) on what row it is failing? start from 5 and take the values from array with -

for i = 5 to (Ubound(LineDetails) - 1) Step 5
			vstrObjectiveID 	= LineDetails(i-4)
			response.write("D E B U G   1) vstrObjectiveID = " & vstrObjectiveID & "<br>")
			vstrInteractionType = LineDetails(i-3)
			vstrResponse 		= LineDetails(i-2)


Open in new window

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

OGSanAuthor Commented:
Below is the javascript function in the module that winds up passing the score info to the ASP program.  Sorry, it's called "EmailResults" but don't let it confuse you.
Re: what row it fails on?  It varies.  The last occurence of the problem had just 3 items out of 5 passed...and the last question was only the 16th (out of 25).  Yet I know that all 25 questions were answered because we can reload the page and it gets sent over...all 25...?!?  So odd.
function EmailResults(strAddress)
	if (!g_oQuizResults.strTitle)
		g_oQuizResults.strTitle = "";
	var g_strSubject = "Quiz Results: " + g_oQuizResults.strTitle;
	var strQuizResults = "";
	var strMainHeader = "\nQuiz Name, Status, Raw Score, Passing Score, Max Score, Min Score, Date Tkn, Time Tkn\n";
	var strMainData = "";
	var strLineData = "";
	var strQuizName = "";
	var strQuizStatus = "";
	var strQuizScore = "";
	var strQuizRaw = "";
	var strQuizPassing = "";
	var strQuizMax = "";
	var strQuizMin = "";
	var strQuizDate = "";
	var strQuizTime = "";

	// Quiz Name
	strQuizName += g_oQuizResults.strTitle;
	// Status
	strQuizStatus += g_oQuizResults.strResult;
	// Score
	strQuizScore += g_oQuizResults.strScore;
	// Raw Score
	strQuizRaw += g_oQuizResults.strPtScore;
	// Passing Score
	strQuizPassing += Math.round((g_oQuizResults.strPassingScore/100) * g_oQuizResults.strPtMax);
	// Max Score
	strQuizMax += g_oQuizResults.strPtMax;
	// Min Score
	strQuizMin += 0;
	// Date
	strQuizDate += GetDate(g_oQuizResults.dtmFinished);
	// Time
	strQuizTime += GetTime(g_oQuizResults.dtmFinished);
// **** 08-09-10 JTF Inactivated following code - do not need this level of detail at this time. 
// **** 09-20-11 JTF ACTIVATED parts of the following quiz line details for saving in new tbl_quiz_detail.
//                   Changed delimiter character from comma to pipe in order to facilitate Split performed
//                   by QM_Post_Results.asp (on the server).
	for (var i = 0; i < g_arrResults.length; i++)
		// Objective Id
		strLineData += g_arrResults[i].strObjectiveId + "|";

		// Interaction Type
		strLineData += g_arrResults[i].strType + "|";

		// Student Response
		var strResponse = g_arrResults[i].strStudentResponse;
		strResponse = ReplaceAll(strResponse, "'", "%27");
		strLineData += strResponse + "|";
		// Result
		strLineData += g_arrResults[i].strResult + "|";
		// Weight
//		strLineData += "1,";
		// Latency
		strLineData += g_arrResults[i].strLatency + "|";

// 09-20-11  JTF  Had to remove \n to get the ObjectiveID to write to the mdb		
//		strLineData += "\n";   
	strQuizLineDtl = strLineData;

// ***** 08-09-10 JTF Formatting for passing fields to ASP program, "QM_Post_Results.asp"
	var sHTML = "";
	sHTML += '<FORM id="formQuiz" method="POST" action="/hr/QuizMaker/QM_Post_Results.asp">';
	sHTML += '<INPUT TYPE="hidden" id="strQuizName" name="strQuizName" VALUE="' + strQuizName + '">';
	sHTML += '<INPUT TYPE="hidden" id="strQuizStatus" name="strQuizStatus" VALUE="' + strQuizStatus + '">';
	sHTML += '<INPUT TYPE="hidden" id="strQuizScore" name="strQuizScore" VALUE="' + strQuizScore + '">';
	sHTML += '<INPUT TYPE="hidden" id="strQuizRaw" name="strQuizRaw" VALUE="' + strQuizRaw + '">';
	sHTML += '<INPUT TYPE="hidden" id="strQuizPassing" name="strQuizPassing" VALUE="' + strQuizPassing + '">';
	sHTML += '<INPUT TYPE="hidden" id="strQuizMax" name="strQuizMax" VALUE="' + strQuizMax + '">';
	sHTML += '<INPUT TYPE="hidden" id="strQuizMin" name="strQuizMin" VALUE="' + strQuizMin + '">';
	sHTML += '<INPUT TYPE="hidden" id="strQuizDate" name="strQuizDate" VALUE="' + strQuizDate + '">';
	sHTML += '<INPUT TYPE="hidden" id="strQuizTime" name="strQuizTime" VALUE="' + strQuizTime + '">';
	// 09-19-11 JTF  Inserting additional detail for each response
	sHTML += '<INPUT TYPE="hidden" id="strQuizLineDtl" name="strQuizLineDtl" VALUE="' + strQuizLineDtl + '">';
	sHTML += '<br><input type="submit"><br>';
	sHTML += '</FORM>';

	document.getElementById("divEmail").innerHTML = sHTML;

Open in new window

can you reproduce the error in Firefox? if so try to debug the javascript.

if some user will put " character what will happen? as I understand the code it will break (some of the text will not be included in the value of the hidden field)
OGSanAuthor Commented:
Thanks, Eyal - I think you've given me the key.  I bet that Javascript module needs to replace those values, otherwise...kablooiee!  I will research this and get back soonest.

BTW, I misspoke in my previous remark, "...we can reload the page it all gets sent over..."  WRONG!
We only get what the Javascript module has sent.
Sorry if that caused misdirection to anyone.
OGSanAuthor Commented:
Eyal - You da man!  That was the culprit: there were double-quotes being used in two of the 50 questions that form the pool of questions for this exam.  When the software happened to select one of those 2 questions - and it tried to save the response with the double-quote - boom!
Problem fixed.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now