Need Javascript to get Day of week back to Lectora

I need to get the day of the week and I believe that I need to use an action to run JS like this:

var d = new Date();

var n = d.getDay();

which would yield the day of the week for n, e.g. returns a 3 for Wednesday.

Question is how can I get the variable n back into Lectora and assign it a Lectora variable?

If anyone has this tip, I would appreciate it.

Thanks,

Louie

Discussion (6)

Thanks Math.

I tried to set up an action

OnShow

Modify Variable "LectoraDay"

Value: Javascript:WeekDay()

and then wrote the External HTML Object:

undefined

but I'm not successful...Am I doing the right thing?

"n" is supposed to return the numerical day of the week.

Any suggestions on how I can fix this is really appreciated.

Thanks Math.

undefinedThe language attribute was deprecated somewhere in 2008, I believe.

You also might want to learn about parseInt.

By the way, this is a question, not a tip, and would be better suited in the questions and answers forum for the future. ;-)

undefined

if your variable in Lectora is called 'myLectoraVariable'... you can set that variable from Javascript by

VarmyLectoraVariable.set("some value or string you want to pass");

When you download eg. my setup http://community.trivantis.com/shared-content/moving-with-variables/

In the Javascript file you find that syntax too... ...eg: Varpos4X.set(posCross4.offsetLeft);

undefined

Main thing to remember is Lectora passes all values as strings.

~Math

You'll have to use a little JavaScript to convert the returned getDay index to the actual name of the weekday. In this example I have a Lectora variable called "whatDay". This can be written more elegantly but it works.

var daysOfTheWeek = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];

today = new Date();

thisDay=today.getDay();

thisDay=daysOfTheWeek[thisDay];

VarwhatDay.set(thisDay);

Quick tip: Add alerts on specific points in your script... either by showing a Lectora message or using console.log("blablaba") or alert("blablabla"). This way you often find errors in your logic....

Discussions have been disabled for this post