home *** CD-ROM | disk | FTP | other *** search
- /* ======================================================================
- OBJECT: com_netobjects_RadioButton
-
- PLATFORMS: Netscape Navigator 4.01 or higher,
- Microsoft Internet Explorer 4.02 or higher
-
- DESC: This object allows developers to create RadioButtons with common built
- in behaviors.
- ====================================================================== */
- function com_netobjects_RadioButton(params) {
- // Public Properties
- this.name = (params.name != null) ? params.name : "";
- this.radioButtonName = (params.radioButtonName != null) ? params.radioButtonName : "";
- this.formName = (params.formName != null) ? params.formName : "";
- this.defaultselected = (params.defaultselected == true) ? params.defaultselected : false;
- this.selectedVal = (params.selectedVal != null) ? params.selectedVal : "";
- this.state = (params.state != null) ? params.state : "";
- this.showLabel = (params.showLabel == true) ? params.showLabel : false;
-
- this.testMode = (params.testMode != null) ? params.testMode : "none"
-
- // Private Properties
- this.radioButtonIndex = null
-
- // Public Methods
- this.render = _RadioButton_render;
- this.getSelected = _RadioButton_getSelected;
- this.setSelected = _RadioButton_setSelected;
-
- // Private Methods
- this.validateProperties = _RadioButton_validateProperties;
-
- // Public Events
- this.onBlur = _RadioButton_onBlur;
- this.onClick = _RadioButton_onClick;
- this.onFocus = _RadioButton_onFocus;
- this.onRender = _RadioButton_onRender;
-
- // Private Events (internal event driven functionality)
-
- // Validate object properties
- this.validateProperties();
-
- // Public Methods ----------------------------------------
- function _RadioButton_render() {
- // Initialize Variables
- var sRadioButtonName = "";
- var svalue = "";
- var sselected = "";
- var slabel = "";
-
- var sonBlur = "";
- var sonClick = "";
- var sonFocus = "";
-
- // Set Variables
- sRadioButtonName = " Name = '" + this.radioButtonName + "'"
-
- // Build Nav & IE shared link events
- sonBlur = " onBlur=\"" + this.name + ".onBlur();\""
- sonClick = " onclick=\"return " + this.name + ".onClick();\""
- sonFocus = " onFocus=\"" + this.name + ".onFocus();\""
- eEvents = sonBlur + sonClick + sonFocus;
-
- // Write HTML
- if (this.state == "hidden") {
- if (this.defaultselected) { // Only print if selected
- document.write( "<Input Type=hidden " + sRadioButtonName + " VALUE = \""+ this.selectedVal + "\"" + eEvents + ">\n");
- }
- } else if (this.state == "read-only") {
- sselected = (this.defaultselected) ? this.selectedVal : ""
- document.write( sselected + "\n");
- } else {
- if (this.showLabel) slabel = " " + this.selectedVal + " ";
-
- svalue = " Value = \"" + this.selectedVal + "\""
- sselected = (this.defaultselected) ? " CHECKED " : ""
- document.write( slabel + "<Input Type=Radio " + sRadioButtonName + svalue + sselected + eEvents + ">\n");
- }
-
- if ((this.state != "read-only") && !((this.state == "hidden") && (!this.defaultselected))) {
- // Set control index if multiple controls exist
- this.radioButtonIndex = eval("window.document." + this.formName + "." + this.radioButtonName + ".length")-1
- if (isNaN(this.radioButtonIndex)) {this.radioButtonIndex=0}
- }
-
- // Fire public events
- this.onRender();
-
- } // END _RadioButton_render
-
-
- /* ======================================================================
-
- METHOD: _RadioButton_validateProperties. If the test mode is set,
- generate error and/or warning messages if required or recommended properties
- are set with invalid property values or are not set at all.
-
- ====================================================================== */
- function _RadioButton_validateProperties() {
- if ((this.testMode.toLowerCase() == "text") || (this.testMode.toLowerCase() == "alerts")) {
- var errors = new Array()
- iIndex = 0;
-
- // Check for errors
- if (this.name == "")
- errors[iIndex++] = "Name is a required property.";
- if (this.radioButtonName == "")
- errors[iIndex++] = "RadioButton name is a required property.";
- if (this.radioButtonName == this.name)
- errors[iIndex++] = "RadioButton name and object name may not be the same.";
- if (this.formName == "")
- errors[iIndex++] = "Form name is a required property.";
-
- // Display errors
- for (var i=0; i<errors.length; i++) {
- if (this.testMode.toLowerCase() == "text")
- document.write( "<BR><HR><B><FONT COLOR=RED>TEST MODE, com_netobjects_Button, '" + this.name + "' : </FONT> " + errors[i] + "</B><HR>\n");
- else
- alert("TEST MODE, com_netobjects_RadioButton, '" + this.name + "' : " + errors[i]);
-
- }
- }
- } // END _RadioButton_validateProperties
-
- /* ======================================================================
-
- METHOD: _RadioButton_getSelected. Gets whether radio button is currently selected.
-
- ====================================================================== */
- function _RadioButton_getSelected() {
- var result = this.defaultselected
- if (this.radioButtonIndex != null) {
- var index = ""
- if (!isNaN(eval("window.document." + this.formName + "." + this.radioButtonName + ".length"))) {
- index = "[" + this.radioButtonIndex + "]"
- }
- result = eval("window.document." + this.formName + "." + this.radioButtonName + index + ".checked")
- }
-
- return result
- } // END _RadioButton_getSelected
-
- /* ======================================================================
-
- METHOD: _RadioButton_setSelected. Sets whether radio button is currently selected.
-
- ====================================================================== */
- function _RadioButton_setSelected(newVal) {
- if (newVal == null) newVal = true;
- var result = false
- if (this.radioButtonIndex != null) {
- var index = ""
- if (!isNaN(eval("window.document." + this.formName + "." + this.radioButtonName + ".length"))) {
- index = "[" + this.radioButtonIndex + "]"
- }
-
- eval("window.document." + this.formName + "." + this.radioButtonName + index + ".checked=" + newVal)
- result = true
- }
-
- return result
- } // END _RadioButton_setSelected
-
-
- // Public Event Handlers ----------------------------------------
- function _RadioButton_onBlur() {
- }
- function _RadioButton_onClick() {
- }
- function _RadioButton_onFocus() {
- }
- function _RadioButton_onRender() {
- }
- // Private Event Handlers ----------------------------------------
-
-
-
- } // END CONSTRUCTOR com_netobjects_RadioButton
-
-