js-modalalert
Alternative to the standard JavaScript alert method.
Tutorial
Sample Parameters in Method Call
onclick="showAlert('Alert Title', 'This is the body of the alert.', 'Close Button', 1)"
- 'Alert Title' fills the alert's title slot.
- 'This is the body of the alert.' fills the body.
- 'Close Button' gives a title to the button responsible for dismissing the alert.
-
1 tells the script to look for an array dictating the form fields.
A value of 0 would tell the method that the alert is strictly presentation.
Returning Information
The method getAlertContents() iterates though the information input by the user and stores it in an array. The array alertInfo is a global variable for easy access for sending to a server or for further processing. The elements are stored in the array in the same order that they appear on the modal alert window.
function getAlertContents(){
for(j = 0; j < buttonValue.length; j++){
var el = document.getElementById('alertForm'+j).value;
alertInfo.push(el);
}
}
Advantages
- Creates custom alert based on parameter inputs.
- Allows for custom title and body.
- Allows addition of blank textfields with predetermined width.
Disadvantages
- Does not function on mobile browsers (iOS confirmed, Android unconfirmed)
- Naming of elements could lead to confusion later on in development
Planned Implementation
- In-line commenting for easy comprehension and implementation.
- Support for more form elements such as buttons and menus.
- Pass an array to the class for creating custom form alerts with ease.
- Support for color change via JS variables.
- Mobile platform support.