/*------------------------------------------------------------------------------ * 1. ÆÄÀϸí: form.js * 2. ¼³ ¸í: Form ¿ä¼Ò ó¸®¿Í °ü·ÃµÈ ÇÔ¼ö¸¦ Á¤ÀÇÇÑ´Ù. * 3. ÀÇÁ¸¼º: ¾øÀ½ * 4. ÀÛ¼ºÀÚ: * 5. ÀÛ¼ºÀÏ: 2006.10.11. -----------------------------------------------------------------------------*/ function getSelectedValue(selectObj) { var selectObj = ref(selectObj); var selectedIndex = selectObj.selectedIndex; return selectObj.options[selectedIndex].value; } /** * Select °´Ã¼¿¡ ¹è¿­¿¡ ÀÖ´Â °ªÀ¸·Î Option °´Ã¼¸¦ * »õ·Î »ý¼ºÇÑ´Ù. ÀÌ ¶§ ÁÖ¾îÁø insertIndex °ªºÎÅÍ * ä¿ö ³ª°¡¹Ç·Î insertIndex °ª ÀÌÀü Ç׸ñµéÀº * »ì¾Æ ³²´Â´Ù. * * @param selectObj Option Ç׸ñÀ» ¼¼ÆÃÇÒ Select °´Ã¼ ÂüÁ¶ ȤÀº ID. * @param optionArr Option Ç׸ñÀ» ´ã°í ÀÖ´Â 2Â÷¿ø ¹è¿­ °´Ã¼. * ÀÌ ¹è¿­ ¿ä¼ÒÀÇ °¢ ¹è¿­ Áß index°¡ 0À롂 value·Î * 1ÀÎ °Ç text·Î »ç¿ëÇÑ´Ù. * @param insertIndex OptionÀ» Ãß°¡ÇÒ Index. * ±× Àü¿¡ ÀÖ´ø ÀÌ Index ÀÌÇÏ Ç׸ñµéÀº ¸ðµÎ »èÁ¦µÈ´Ù. */ function setOption(selectObj, optionArr, insertIndex) { if ( typeof(selectObj) == "string" ) selectObj = document.getElementById(selectObj); if ( insertIndex == undefined ) insertIndex = 0; selectObj.options.length = insertIndex ; if ( optionArr == undefined || optionArr == null || optionArr.length == 0 ) return; for ( var i = 0; i < optionArr.length; i++ ) { var text = "(" + optionArr[i][0] + ") " + optionArr[i][1]; selectObj.options[i + 1] = new Option(text, optionArr[i][0]); } } /** * Select °´Ã¼ ³»¿¡¼­ ÁÖ¾îÁø °ªÀÌ ÀÖ´ÂÁö ã¾Æ * Index¸¦ µ¹·Á ÁØ´Ù. ¾øÀ¸¸é -1À» µ¹·Á ÁØ´Ù. * * @param selectObj Select °´Ã¼ ÂüÁ¶ ȤÀº ID. * @param value Index¸¦ ãÀ¸·Á°í ÇÏ´Â °ª. * * @return selectObjÀÇ Option Ç׸ñ Áß value ¼Ó¼ºÀÌ ÁÖ¾îÁø °ªÀÎ Ç׸ñÀÇ Index. * ¾øÀ¸¸é -1. */ function indexOfSelect(selectObj, value) { if ( typeof(selectObj) == "string" ) selectObj = document.getElementById(selectObj); var index = -1; for ( var i = 0; i < selectObj.length; i++ ) { if ( selectObj.options[i].value == value ) { index = i; break; } } return index; } /** * SelectÀÇ optionÁß value Ç׸ñÀÇ °ªÀ» °¡Áö´Â * optionÀÌ ¼±ÅÃµÈ °ÍÀ¸·Î ¼³Á¤ÇÑ´Ù. * * @param selectObj Select °´Ã¼ ÂüÁ¶ ȤÀº ID. * @param value ¼±ÅÃµÈ °ÍÀ¸·Î ÇÏ·Á´Â °ª. */ function setSelect(selectObj, value) { if ( typeof(selectObj) == "string" ) selectObj = document.getElementById(selectObj); if ( value == undefined ) value = ""; selectObj.selectedIndex = indexOfSelect(selectObj, value); } var ENABLED_BGCOLOR = ""; var DISABLED_BGCOLOR = "#CDCDCD"; /** * ÁÖ¾îÁø °´Ã¼ Disable ¿©ºÎ¸¦ disabled °ªÀ¸·Î ¼³Á¤Çϰí * ¹è°æ»öÀ» Á¶ÀýÇÑ´Ù. * * @param obj Disabled ¿©ºÎ¸¦ ¼¼ÆÃÇÒ °´Ã¼ ÂüÁ¶ ȤÀº ID. * @param disabled Disabled ¿©ºÎ. Disable ½ÃŰ·Á¸é true, Enable ½ÃŰ·Á¸é false. */ function setDisabled(obj, disabled) { if ( typeof(obj) == "string" ) obj = document.getElementById(obj); obj.disabled = disabled; obj.style.backgroundColor = disabled ? DISABLED_BGCOLOR : ""; } var READONLY_BGCOLOR = "#EFEFEF"; /** * ÁÖ¾îÁø °´Ã¼ ReadOnly ¿©ºÎ¸¦ disabled °ªÀ¸·Î ¼³Á¤Çϰí * ¹è°æ»öÀ» Á¶ÀýÇÑ´Ù. * * @param obj readOnly ¿©ºÎ¸¦ ¼¼ÆÃÇÒ °´Ã¼ ÂüÁ¶ ȤÀº ID. * @param readOnly ReadOnly ¿©ºÎ. readOnly ½ÃŰ·Á¸é true, Enable ½ÃŰ·Á¸é false. */ function setReadOnly(obj, readonly) { if ( typeof(obj) == "string" ) obj = document.getElementById(obj); obj.readOnly = readonly; obj.style.backgroundColor = readonly ? READONLY_BGCOLOR : ""; }