JavaScript Source: Tạo sự kiện liên kết giữa DropDownList và TextBox.

Đoạn mã JavaScript đơn giản nhau sẽ giúp bạn tạo một hiệu ứng sự kiện chuyển đổi đơn giản, khi bạn chọn một giá trị trong DropDownList thì giá trị trong TextBox sẽ hiển thị một thông tin tương ứng mà bạn định nghĩa cho nó. Đoạn script thường dùng để áp dụng khi bạn có một danh sách nào đó và muốn người dùng chọn, nhưng do tên trong danh sách quá ngắn người dùng không thể hiểu được thì bạn có thể sử dụng hiệu ứng này để khi người dùng chọn sẽ có được thông tin giải thích về cái mà họ đang chọn lựa.


Hỗ trợ trình duyệt: Firefox, IE, Chrome, Safari, Opera




JavaScript Source:
<html>

<head>
    <script language="JavaScript">
        <!-- Begin
        var messages = new Array(6);
        messages[0] = "";
        messages[1] = "blog.vnlives.net is my website.";
        messages[2] = "Your Account is base.";
        messages[3] = "Your Account is share.";
        messages[4] = "Your Account is public.";
        messages[5] = "Your Account is private.";

        function messageReveal() {
            var messageindex = document.messageForm.messagePick.selectedIndex
            document.messageForm.messageField.value = messages[messageindex];
        }
        // End -->
    </script>
    <!-- STEP TWO: Put this code into the BODY of your HTML document  -->
</head>

<body>

    <center>
        <form name="messageForm">
            <p>
<select name="messagePick" onchange="messageReveal()">
<option value="0">The Menu Message</option>
<option>vnlives.net</option>
<option>Account Base</option>
<option>Account Share</option>
<option>Account Public</option>
<option>Account Private</option>
</select>
            </p>
<br>
            <p>
<textarea name="messageField" rows="5" cols="41" wrap="virtual"></textarea>
</p>
        </form>
    </center>

</body>

</html>





No comments:

Post a Comment