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

Passing values to ASP from Javascript

Hi, Experts -
I am trying to use Javascript to pass a quiz-score value to an ASP program.  I am not sure how Javascript works - but the quiz software (Articulate's Storyline) allows for "triggers" (e.g., button-clicks) to execute Javascript code.  The software also stores the quiz-score value in a variable that can be accessed by Javascript.  

I put together the following bit of code and need someone who knows Javascript to validate it for me, please:
function Script1()
{
// get Storyline player
var p = GetPlayer();

// get quiz score
var score = p.GetVar("Results.ScorePercent");

//DEBUG: display value on screen
document.write("Score to be passed: " + score); 

// pass score to ASP program to eventual database update
var sHTML = "";
sHTML += "<form id='formScore' method='post' action='/hr/Storyline/SL_Post_Scores.asp'>";
sHTML += "input type='hidden' id='Score' name='Score' value= '" + score + "'>";
sHTML += "<br><input type='submit'><br>";
sHTML += "<form>";
document.getElementById("formScore").submit();
}

Open in new window

Thank you!
0
OGSan
Asked:
OGSan
  • 7
  • 4
1 Solution
 
plummetCommented:
It looks OK to me, but can you not just pass the score as part of the URL?

eg

function Script1()
{
// get Storyline player
var p = GetPlayer();

// get quiz score
var score = p.GetVar("Results.ScorePercent");

//DEBUG: display value on screen
document.write("Score to be passed: " + score); 

// pass score to ASP program to eventual database update
window.location.href="/hr/Storyline/SL_Post_Scores.asp?score=" + score;
}

Open in new window

I'm not exactly a world authority on Javascript though!
0
 
OGSanAuthor Commented:
Thanks for the reply, plummet.  I'll give that method a shot since I'm not getting ANYTHING AT ALL from my method. :-(
0
 
plummetCommented:
You could test it with a score that you know exists, by hard coding that in ie:

window.location.href="/hr/Storyline/SL_Post_Scores.asp?score=1234";

Open in new window


Just to make sure the page gets loaded.
0
Industry Leaders: 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!

 
OGSanAuthor Commented:
Thanks, plummet.  I'm unable to get any action at all.  Perhaps what I'm trying to do is just not possible.  Here's a quick summary:
I am working with the output from an eLearning course created using Articulate's Storyline software.  The output results in a course that plays as Flash movie in a browser window.  On the final slide, a button has been created with "code behind" if you will that allows it to "Execute Javascript."  The code behind file creates a User.js module - with the function above (Script1) containing the Javascript code entered.
I modified the contents of the Script1 code to use your suggestion and reran the course.  Just as with my original code, when the button was clicked - nothing happened at all.
Here's a screenshot of the slide with the button.Trigger test
0
 
plummetCommented:
Hi OGSan

I'm not familiar with Articulate's Storyline but, having looked at their web pages, it seems to allow this sort of thing. However what do you do to tell the system that you want to put code behind the submit button?

Also, the function is called "script1", was this name given by the system? How does Storyline know that when you press the button it is to run "script1"?

If there is any more code you can send it would be useful. It seems to me that the button is not running the code, for example if you simply entered the following code does anything happen?

function Script1()
{
alert("Hello, the button has been pressed");
}

Open in new window

If not, then the javascript is not being called when the button is pressed. If you do ge a popup message then at least we know the link is working

Regards
John
0
 
OGSanAuthor Commented:
Thanks for hanging in there with me on this, John.
I inserted the alert and - voila! - it shows up!
alert shows up!
0
 
OGSanAuthor Commented:
I replaced the "document.write" with another "alert" box to display a second box indicating the score value being passed - this box never opens.  Only the first alert is displayed.  Here is the entire javascript User.js module, includes the "Hello" alert:
function ExecuteScript(strId)
{
  switch (strId)
  {
      case "60gTp9hQEKK":
        Script1();
        break;
  }
}

function Script1()
{
alert("Hello, the button has been pressed");

// get Storyline player
var p = GetPlayer();

// get score
var score = p.GetVar("Results.ScorePercent");

//display value on screen
alert("Score to be passed: " + score); 

// pass score to ASP program to eventual database update
var sHTML = "";
sHTML += "<form id='formScore' method='post' action='/hr/Storyline/SL_Post_Scores.asp'>";
sHTML += "input type='hidden' id='Score' name='Score' value= '" + score + "'>";
sHTML += "<br><input type='submit'><br>";
sHTML += "<form>";
document.getElementById("formScore").submit();
}

Open in new window

0
 
plummetCommented:
Hi

I'm still thinking about this, and I reckon you should try to dummy up the score something like this:

function ExecuteScript(strId)
{
  switch (strId)
  {
      case "60gTp9hQEKK":
        Script1();
        break;
  }
}

function Script1()
{
alert("Hello, the button has been pressed");

// get Storyline player
var p = GetPlayer();

// get score
//var score = p.GetVar("Results.ScorePercent");
var score = 20;

//display value on screen
alert("Score to be passed: " + score); 

// pass score to ASP program to eventual database update
var sHTML = "";
sHTML += "<form id='formScore' method='post' action='/hr/Storyline/SL_Post_Scores.asp'>";
sHTML += "input type='hidden' id='Score' name='Score' value= '" + score + "'>";
sHTML += "<br><input type='submit'><br>";
sHTML += "<form>";
document.getElementById("formScore").submit();
}

Open in new window


If that works then it's not able to retrieve the variable Results.ScorePercent. If not then we will have to think again!
0
 
OGSanAuthor Commented:
Hi, John -
I inserted your code into the module and tested it - and the second msg box shows up with the "score to be passed: 20" displayed.  So, yes - there is something wrong with the value being retrieved from the Storyline variable.
Also, I inserted an additional line of code at Line 31 below and now the ASP program is being invoked...!  But for some reason, the Score value of 20 is not being retrieved.
Here is the User.js code with the new line of code inserted (Line 31) near bottom:
function ExecuteScript(strId)
{
  switch (strId)
  {
      case "60gTp9hQEKK":
        Script1();
        break;
  }
}

function Script1()
{
alert("Hello, the button has been pressed");

// get Storyline player
var p = GetPlayer();

// get score
//var score = p.GetVar("Results.ScorePercent");
var score = 20;

//display value on screen
alert("Score to be passed: " + score); 

// pass score to ASP program to eventual database update
var sHTML = "";
sHTML += "<form id='formScore' method='post' action='/hr/Storyline/SL_Post_Scores.asp'>";
sHTML += "input type='hidden' id='Score' name='Score' value= '" + score + "'>";
sHTML += "<br><input type='submit'><br>";
sHTML += "<form>";
document.getElementById("divEmail").innerHTML = sHTML;
document.getElementById("formScore").submit();
}

Open in new window

And here is the simple little ASP program that displays the date/time and the Score value being passed to it:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<%
vPageUpdateDte = Now()
Response.Buffer=True
	
strScore = Request.Form("Score")
'D E B U G
Response.write("Today is: " & vPageUpdateDte)
Response.write("<br /> Score received: " & strScore)
%>

Open in new window

0
 
OGSanAuthor Commented:
I'm able to display the values passed from the Javascript module now...but only the hardcoded values and NOT the Storyline variable  :-(
Here's the display:
Trigger test AAnd the proof the value was successfully retrieved:
Trigger test BGetting closer to solving this!
Something is definitely wrong with the Storyline variable.
0
 
OGSanAuthor Commented:
Sorry - I forgot to return and post the resolution to this problem:  Storyline variables have to be defined within the process of building a course.  Once these variables are defined, they then become accessible to the program - and their values can be captured and passed on.  Geez Louise this took a while to figure out (a task made especially difficult because I don't own a copy of Storyline!), but it got done and documented.  thanks for the replies, John!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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