This is a migrated thread and some comments may be shown as answers.

Resetting all controls on a form

1 Answer 201 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 2
Joe asked on 27 Nov 2013, 03:22 AM
I have several separate forms that I want to add a "reset" or "clear" button to. What I'd like is a way to blanket reset all controls to their initial state.

The forms are built entirely from Telerik controls.

What is the best to do this? I'd like the ability to use a single piece of code (javascript) to be included in all pages.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 27 Nov 2013, 08:52 AM
Hi Joe,

Please have a look into the following code snippet to Reset the controls in RadButton Click event.

ASPX:
<telerik:RadTextBox ID="text1" runat="server">
</telerik:RadTextBox>
<br />
<telerik:RadTextBox ID="text2" runat="server">
</telerik:RadTextBox>
<br />
<telerik:RadDatePicker ID="date1" runat="server">
</telerik:RadDatePicker>
<br />
<telerik:RadComboBox ID="RadComboBox1" runat="server">
    <Items>
        <telerik:RadComboBoxItem Text="I" runat="server" />
    </Items>
</telerik:RadComboBox>
<telerik:RadButton ID="RadButton1" runat="server" AutoPostBack="false" OnClientClicked="Clear"
    Text="Clear">
</telerik:RadButton>

JavaScript:
<script type="text/javascript">
    function Clear(sender, args) {
        var elements = document.getElementsByTagName("input");
        for (var i = 0; i < elements.length; i++) {
            if (elements[i].type == "text") {
                elements[i].value = "";
            }
        }
    }
</script>

Thanks,
Shinu.
Tags
General Discussions
Asked by
Joe
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Share this question
or