|
JavaScript in SSI Web
|
|
| <script type="text/javascript">
|
| <!--
|
|
|
| alert("Welcome to the survey.");
|
|
|
| //-->
|
| </script>
|
| <a href="#" onclick="alert('hello');">Click Here</a>
|
| <script type="text/javascript" src="[%GraphicsPath()%]CustomJavaScriptFile.js"></script>
|
| var NumDaysInWeek = 7;
|
| var MonthName = "March";
|
| var Q1Value = SSI_GetValue("Q1");
|
| var BlueChosen = SSI_GetValue("FavColors_1");
|
| var NumDaysInWeek = 7;
|
| var Weeks = [%NumWeeks%];
|
| document.write(NumDaysInWeek * Weeks);
|
| var Weeks = 4;
|
| var Name = "[%LastName%]";
|
| var Name = "Smith";
|
| var ItemList = [1,2,3,4,5,6,7];
|
| document.write(ItemList[0]);
|
| var Age = SSI_GetValue("Q1");
|
|
|
| if(Age < 18)
|
| {
|
| alert("You do not qualify for this survey.");
|
| }
|
|
|
| var Age = SSI_GetValue("Q1");
|
|
|
| if(Age < 18)
|
| {
|
| alert("You do not qualify for this survey.");
|
| }
|
| else if(Age < 65)
|
| {
|
| alert("You qualify for group 1.");
|
| }
|
| else if(Age >= 65 && Age <= 125)
|
| {
|
| alert("You qualify for group 2.");
|
| }
|
| else
|
| {
|
| alert("Are you sure you are older than 125?");
|
| }
|
| · | "&&" for AND
|
| · | "||" for OR
|
| · | "==" for equal
|
| · | <, >, <=, >=, etc.
|
| var myArray = [1,2,3,4,5];
|
| var i = 0;
|
| var sum = 0;
|
|
|
| for(i = 0; i < myArray.length; i++)
|
| {
|
| sum += myArray[i];
|
| }
|
|
|
| alert(sum);
|
| function AddTwo (Num1, Num2)
|
| {
|
| var Result = Num1 + Num2;
|
|
|
| return Result;
|
| }
|
|
|
| alert(AddTwo(4, 6)); //The value 10 will appear in a pop-up box.
|
| alert(AddTwo(56, 33); //The value 89 will appear in a pop-up box.
|
| var Q1Obj = document.mainform["Q1"];
|
| var Q1Obj = SSI_GetFromObject("Q1");
|
| Q1Obj.value = 5;
|
| Q1Obj.addEvent("keyup", SetToFive);
|
|
|
| function SetToFive()
|
| {
|
| this.value = 5;
|
| }
|
| SSI_GetValue("QuestionName")
|
| if([%respondentAge%] >= SSI_GetValue("fatherAge"))
|
| if(37 >= SSI_GetValue("fatherAge"))
|
| Returns the current value for the specified QuestionName, for any question type (radio, checkbox, numeric, etc.). A zero ("0") is returned for questions that have been left empty.
|
|
|
| Example:
|
| var Num1 = SSI_GetValue("Q1"); // returns the value of question Q1
|
| var FirstStateChecked = SSI_GetValue("State_1"); // If the first check box of question "State" is checked 1 will be returned, otherwise 0.
|
| Returns the object associated with the form element on the page for QuestionName.
|
|
|
| Example:
|
| var Num1Obj = SSI_GetFormObject("Q1"); // Assigns the form object for question "Q1" to "Num1Obj".
|
| Num1Obj.value = 46; // Assign the value of 46 to the Q1 question.
|
| Round "Number" to "NumDecimalPlaces".
|
| Example:
|
| var Value1 = SSI_RoundNumber(SSI_GetValue("Q1"), 2); // SSI_GetValue returns the value for Q1 it is then rounded to 2 decimal places.
|
| alert(Value1); // Assuming Q1 was 45.236 the Value1 would yield 45.24
|
|
|
| Formats a number with the thousands symbol and decimal symbol.
|
|
|
| Example:
|
| var FormatValue = SSI_PriceFormat(5123693.25, ",", "."); // 5,123,693.25 is returned.
|
|
|
| SSI_CustomGraphicalCheckbox is a function that has been provided so that you can write custom code that gets called when a graphical checkbox is clicked. This function must be defined by you in your custom JavaScript. The function will be called by SSI Web's system JavaScript each time a check box is clicked.
|
|
|
| GraphicalCheckboxObj represents the graphical item on the page that is being clicked. InputObj is the actual hidden checkbox on the page that the graphical checkbox represents. blnCheck is true if the checkbox has been checked, otherwise it is false.
|
|
|
| Example:
|
| function SSI_CustomGraphicalCheckbox(GraphicalCheckboxObj, InputObj, blnCheck)
|
| {
|
| if(InputObj.name == "mySelect_1" && blnCheck == true)
|
| {
|
| alert("The first box was checked");
|
| }
|
| }
|
| SSI_CustomGraphicalRadiobox is a function that has been provided so that you can write custom code that gets called when a graphical radio button is clicked. This function must be defined by you in your custom JavaScript. The function will be called by SSI Web's system JavaScript each time a radio box is clicked.
|
|
|
| GraphicalRadioboxObj represents the graphical item on the page that is being clicked. InputObj is the actual hidden radio button on the page that the graphical radio button represents. When ever this function gets called the radio button represented by InputObj will have been checked.
|
|
|
| Example:
|
| function SSI_CustomGraphicalRadiobox(GraphicalRadioboxObj, InputObj)
|
| {
|
| if(InputObj.name == "mySelect")
|
| {
|
| alert("A radio button with the value " + InputObj.value + " has been selected.");
|
| }
|
| }
|
|
|
| Turn on script error reporting. This is done in Internet Explorer by clicking Tools | Internet Options | Advanced. Under the Advanced tab go to the Browsing section and check Display a notification about every script error. This is extremely useful in alerting you to mistakes in your code.
|
|
|
| Use the "alert( )" function. If you are unsure what certain values are at certain points in your code, you can print them out to the screen by using the "alert( )" function. For example:
|
|
|
| alert("My value at this point is: " + SSI_GetValue("Q1"));
|
|
|
| Firefox has a plug-in named "Firebug" that provides a powerful JavaScript debugger.
|
|
|
| Test your custom JavaScript in multiple browsers (e.g. Microsoft Internet Explorer, Firefox, etc.).
|