user603007
user603007

Reputation: 11794

how to trigger change event in javascript?

i am trying to make my 4th checkbox enabled as soon as there is a new value in my textbox (myinput). If it is empty than disable this. At the moment you have to tab out before the changing event is triggered? Also:how can I check for an empty textbox?

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input id="myinput" type="text" onchange="Changing();" />
        <asp:CheckBoxList runat="server" TextAlign="Right">
            <asp:ListItem Text="een">

            </asp:ListItem>
            <asp:ListItem Text="twee">

            </asp:ListItem>
            <asp:ListItem Text="drie">

            </asp:ListItem>
            <asp:ListItem Text="vier">

            </asp:ListItem>
        </asp:CheckBoxList>
    </div>
    </form>
</body>
</html>
<script language="javascript">

    function Changing() {
        //alert('changing', document.getElementById('myinput').value);
        if (document.getElementById('myinput').value == '') {
            document.getElementById('ctl02_3').disabled = true;
        }
        else {
            document.getElementById('ctl02_3').disabled = false;
        }
    }

</script>

Upvotes: 0

Views: 231

Answers (1)

musefan
musefan

Reputation: 48415

You can use the onkeyup event which will fire as the textbox value changes.

See here: http://www.w3schools.com/jsref/event_onkeyup.asp

Also the onkeydown and onkeypress events will yield similar results

Upvotes: 1

Related Questions