Shahin
Shahin

Reputation: 12861

Clear all textboxes client side

Can I Simulate this Code With JQUERY or Javascript?

    IEnumerable<TextBox> Textboxes = (from c in pnlform.Controlswhere    object.ReferenceEquals(c.GetType(), typeof(TextBox))c).AsEnumerable().Cast<TextBox>();
foreach (TextBox item in Textboxes) {
item.Text = string.Empty;
}

i want to clear all textboxes without any roundtrip to server.

Upvotes: 0

Views: 4765

Answers (4)

zzzzBov
zzzzBov

Reputation: 179256

Use the reset button. It will reset all ( input | select | textarea ) elements within a form to their default values. The default values are specified by the element like so:

<input type="text" name="someName" value="this is a default value" />

with radio buttons and check boxes, it will return them to their default checked state.

Edit to add:
Reset buttons work well as a "cancel" button if you have a form where you are making changes to existing data.

Upvotes: 1

rahul
rahul

Reputation: 187110

Seems like you are trying to clear textboxes inside a panel pnlform. So in your selector you can give a context

$("input:text", "#yourpanelid").val('');

Upvotes: 2

Gregg B
Gregg B

Reputation: 13747

In a click function I have a link with class reset:

$('.reset').click(function(){
    $(':input','#formID')
     .val('')   
}); 

Upvotes: 1

RPM1984
RPM1984

Reputation: 73123

Don't really understand that code, but to clear a textbox with jQuery:

$('someselector').val('');

So to clear all textboxes on a page:

$('input[type=text]').val('');

Or you could use good old' form.reset()

Upvotes: 3

Related Questions