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.
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.
Share Improve this question edited Nov 9, 2010 at 5:00 zzzzBov 179k56 gold badges327 silver badges371 bronze badges asked Nov 9, 2010 at 4:46 ShahinShahin 12.9k40 gold badges129 silver badges209 bronze badges 3- 1 JavaScript is an event-driven language. What circumstances would lead to the elements being cleared? If you want the user to click a button to clear a form, you should use the <input type="reset" /> button. What I'm trying to get at is that you need to provide more details. – zzzzBov Commented Nov 9, 2010 at 4:50
- @zzzBov : You Are Right i have to use <input type="reset" /> button. does it work for all controls ? like checkbox radio button and... – Shahin Commented Nov 9, 2010 at 4:54
-
1
it works for all controls in the same
form
as your cancel button. They all will be reset to their initial value. – Maksim Vi. Commented Nov 9, 2010 at 5:36
4 Answers
Reset to default 3Don'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()
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('');
In a click function I have a link with class reset:
$('.reset').click(function(){
$(':input','#formID')
.val('')
});
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.