use the following construct to cclear the value of textbox :- $('#<id of the textbox>').attr('value', '');
Note : text of textbox is actually displayed as value attribute in the markup so you need to use the attr() function and set the value property to empty.
2177
Member
375 Points
325 Posts
JQuery to clear textbox
Jun 18, 2009 03:28 PM|LINK
Hi all,
I am new to the JQuery. I need to clear textboxes and set the first item in the dropdownlist. Could you please show me code to do so?
SP
Please do "Mark As Answer" if this helps you.
RatheeshC
Contributor
5652 Points
1198 Posts
Re: JQuery to clear textbox
Jun 18, 2009 04:20 PM|LINK
Hi,
Clear Text box
$(
"#<%=txtTest.ClientID%>").val('');For drop down
$(
"#<%=ddlTest.ClientID%>").val('0');Thanks
Ratheesh
Ratheesh
Please mark it as answer if it resolves your issue.
2177
Member
375 Points
325 Posts
Re: JQuery to clear textbox
Jun 18, 2009 04:45 PM|LINK
Hi Ratheesh,
Thanks for a quick reply.
Well, I did exactly the way you have suggested. That is, $('#<%=txtCardHolder.ClientID %>').val('');
But it gives "Object expected" browser error.
SP
Please do "Mark As Answer" if this helps you.
RatheeshC
Contributor
5652 Points
1198 Posts
Re: JQuery to clear textbox
Jun 18, 2009 04:55 PM|LINK
Hi,
Make sure that you are including the JQuery file in th page .
Put the code inside jQuery(document).ready(function($){
--- Put code here---
}
Thanks
Ratheesh
Ratheesh
Please mark it as answer if it resolves your issue.
Pawan_Mishra
Star
8869 Points
1293 Posts
Re: JQuery to clear textbox
Jun 18, 2009 04:58 PM|LINK
Hi
use the following construct to cclear the value of textbox :- $('#<id of the textbox>').attr('value', '');
Note : text of textbox is actually displayed as value attribute in the markup so you need to use the attr() function and set the value property to empty.
Pawan Mishra
Moving from Asp.Net to WPF and SilverLight .....
.Net 360°
2177
Member
375 Points
325 Posts
Re: JQuery to clear textbox
Jun 18, 2009 05:09 PM|LINK
Could you please tell me your mean by "include jquery file in the page"?
SP
Please do "Mark As Answer" if this helps you.
RatheeshC
Contributor
5652 Points
1198 Posts
Re: JQuery to clear textbox
Jun 18, 2009 05:12 PM|LINK
Hi,
Like this<
script src="../Js/jquery-1.2.6.js" type="text/javascript"></script>you have to refer the JQuery file in your page
Thanks
Ratheesh
Ratheesh
Please mark it as answer if it resolves your issue.
novogeek
Participant
935 Points
154 Posts
Re: JQuery to clear textbox
Jun 18, 2009 06:54 PM|LINK
Hi,
As said above, if you are missing reference to jQuery file, you will get that error. If your controls are placed in nested controls(like in server side panels), you will face client side reference issues. This is the best way to eliminate such issues: http://encosia.com/2009/06/09/11-keystrokes-that-made-my-jquery-selector-run-10x-faster/
Hope it helps [:)]
Infosys Technologies Ltd, Hyderabad, India,
Microsoft MVP
Website: NovoGeek.com | Twitter: NovoGeek
***Please "Mark as Answer" if this reply helps you***
novogeek
Participant
935 Points
154 Posts
Re: JQuery to clear textbox
Jun 18, 2009 06:55 PM|LINK
Hi,
As said above, if you are missing reference to jQuery file, you will get that error. If your controls are placed in nested controls(like in server side panels), you will face client side reference issues. This is the best way to eliminate such issues: http://encosia.com/2009/06/09/11-keystrokes-that-made-my-jquery-selector-run-10x-faster/
Hope it helps [:)]
Infosys Technologies Ltd, Hyderabad, India,
Microsoft MVP
Website: NovoGeek.com | Twitter: NovoGeek
***Please "Mark as Answer" if this reply helps you***
2177
Member
375 Points
325 Posts
Re: JQuery to clear textbox
Jun 18, 2009 08:35 PM|LINK
I got it...
Thanks a lot!
SP
Please do "Mark As Answer" if this helps you.