Clear INPUT TextBox and DropDownList (HTML SELECT) Items using jQuery on Button Click

Last Reply on May 08, 2014 04:48 AM By Azim

Posted on May 08, 2014 03:43 AM

Hello team,

I am tryed to use Jquery for clear text box value and set detafult value to drop down list using asp.net c#. Asp button control.

My code as per follows

 

 <script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#btnClear").click(function () {
                $("#txtCityAbbv").val('');
                alert('Hello');
            });
        });
    </script>

 

<input type="button" id="btnClear" value="Clear" class="save" onclick="return ClearField();" />

By clicking Clear button alert msg show, but i m not able to clear text box. Please help. Thanks.

Posted on May 08, 2014 04:48 AM

This way

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("[id*=btnClear]").click(function () {
                $("[id*=txtCityAbbv]").val('');
                $("[id*=sFruits]").empty();
                alert('Hello');
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input type="text" id="txtCityAbbv" name="name" value="Hello" />
        <select id="sFruits">
            <option value="1">Mango</option>
            <option value="2">Banana</option>
            <option value="3">Apple</option>
        </select>
        <hr />
        <input type="button" id="btnClear" name="name" value="Clear" />
    </div>
    </form>
</body>
</html>

Demo