Valid JavaScript not working

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
Jdubs
Posts: 73
Joined: Fri Dec 19, 2014

22 Dec 2014

Scenario:

I input JavaScript code, press "save," test client-side form, and form works.
I input additional JavaScript code, "press save," test client-side form, and form no longer works.
I remove additional JavaScript code, "press save," test client-side form, and form still does not work.
To be clear, the code from Line 1 and Line 3 are exactly the same.

Why does the code no longer work?

Jdubs
Posts: 73
Joined: Fri Dec 19, 2014

22 Dec 2014

Here's the EXACT scenario:


Line 1 Code (Works!)

//Calculate Date

var calcDate = new Date();

var Month = calcDate.getMonth() + 1;

var Day = calcDate.getDate();

var Year = calcDate.getFullYear();

var vStartDate = Month + "/" + Day + "/" + Year;

var Hour = Math.round(calcDate.getHours());

var Minute = calcDate.getMinutes();

var ampm = Hour >= 12 ? 'PM' : 'AM';


//Pre-populate Date & Time

if(fd.field('StartTime').value() === "")

{

fd.field('StartTime').value(vStartDate);

fd.field('sTime').value(Hour + ":" + Minute + " " + ampm);

};



Line 2 (Does not work!)

//Calculate Date

var calcDate = new Date();

var Month = calcDate.getMonth() + 1;

var Day = calcDate.getDate();

var Year = calcDate.getFullYear();

var vStartDate = Month + "/" + Day + "/" + Year;

var Hour = Math.round(calcDate.getHours());

var Minute = calcDate.getMinutes();

var ampm = Hour >= 12 ? 'PM' : 'AM';

var 12Hour = Hour > 12 ? Hour - 12 : Hour; //New Line of Code


//Pre-populate Date & Time

if(fd.field('StartTime').value() === "")

{

fd.field('StartTime').value(vStartDate);

fd.field('sTime').value(Hour + ":" + Minute + " " + ampm); //New Variable

};


Line 3 (DOES NOT WORK!)


I simply un-do the two lines that I modified in Line 2, save it ... and then it doesn't work. (even though it is EXACTLY the same as line 1)

Jdubs
Posts: 73
Joined: Fri Dec 19, 2014

22 Dec 2014

*sigh* Sorry.


I input variable 12Hour on Line 2 on the pre-population line. (the one that I flag //New Variable)

Jdubs
Posts: 73
Joined: Fri Dec 19, 2014

22 Dec 2014

One additional note, I just verified this:

When I CLEAR all the JavaScript code, SAVE it, THEN re-paste the original code, then save it again ... the JavaScript code works again.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 5 guests