phpschool.com 출처

nate : yanione@nate.com // 작은머리 님

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title> new document </title>
        <meta name="generator" content="editplus" />
        <meta name="author" content="" />
        <meta name="keywords" content="" />
        <meta name="description" content="" />
        <meta http-equiv="Content-Type" content="text/html; charset=euc-kr" />


        <script type="text/javascript">
        //<![CDATA[

            function fn_select_form_onchange(){

                top.location.href = "?selected_idx=" + document.getElementById("form_selected").selectedIndex;
            }

            function fn_form_select_selected(intSelectedIndex){

                document.getElementById("form_selected").options[intSelectedIndex].selected = true;
            }

            function fn_form_select_viewer(intSelectedIndex){

                var strSelectedValue = document.getElementById("form_selected").options[intSelectedIndex].innerHTML;

                document.getElementById("selected_index_viewer").innerHTML = "selectedIndex = " + strSelectedValue;

            }

            //이벤트등록
            function fnAddEvent(objObject, strEvent, strEventstring, strInputEventType)
            {
                strInputEventType    = strInputEventType == "string" ? strInputEventType.toLowerCase() : "";

                var blsEventString    = strInputEventType == 'string' ? true : false;

                strEvent    = strEvent.toLowerCase();

                if(strEvent.substring(0, 2) == 'on')
                {
                    strEvent    = strEvent.substring(2);
                }

                try
                {
                    if(objObject.attachEvent)
                    {
                        if(blsEventString)
                            objObject.attachEvent('on'+ strEvent, function (){ eval(strEventstring); });
                        else
                            objObject.attachEvent('on'+ strEvent, strEventstring);
                    }
                    else if(objObject.addEventListener)
                    {
                        if(blsEventString)
                            objObject.addEventListener(strEvent, function (){ eval(strEventstring); }, false);
                        else
                            objObject.addEventListener(strEvent, strEventstring, false);
                    }
                }
                catch (e)
                {
                    window.status    = 'Error : 이벤트를 추가하지 못했습니다. ['+ strEventstring +']';
                    return false;
                }

                blsEventString    = null;

                return true;
            }


            function fn_requestForm(strKey){


                var strRtnValue = null;

                if (strKey){

                    var strLocationUrl = window.location.href;

                    if (strLocationUrl !== "" && strLocationUrl.split("?").length > 1){

                        var strParameter = strLocationUrl.split("?")[1];

                        for (var intKey = strParameter.split("&").length; intKey--;){

                            var strCurrentKey = strParameter.split("&")[intKey].split("=")[0];
                            var strCurrentKeyValue = strParameter.split("&")[intKey].split("=")[1];

                            if (strCurrentKey.toLowerCase() === strKey.toLowerCase()){

                                strRtnValue = strCurrentKeyValue;
                                break;
                            }
                        }
                    }


                    return strRtnValue;
                }
            }

            window.onload = function(){

                var reqIndex = window.fn_requestForm("selected_idx");

                if (reqIndex){

                    fn_form_select_selected(reqIndex);
                    fn_form_select_viewer(reqIndex);
                }

                fnAddEvent(document.getElementById("form_selected"), "change", function(){ fn_select_form_onchange(); });
            }

 

        //]]>
        </script>

        <style type="text/css">
        <!--

            #selected_index_viewer{

                position:relative;
                float:left;


                width:500px;
                height:500px;

                text-align:center;
                color:white;

                background:black;

            }


            #select_container{

                position:relative;
                float:left;

                text-align:center;

            }

        //-->
        </style>

    </head>

    <body>

        <div id="selected_index_viewer"></div>
        <div id="select_container">
            셀렉트 박스 :
            <select id="form_selected">
                <option>----</option>
                <option>menu1</option>
                <option>menu2</option>
                <option>menu3</option>
                <option>menu4</option>
                <option>menu5</option>
                <option>menu6</option>
            </select>
        </div>

    </body>
</html>