Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Mar 10, 2008 11:54 AM by NC01
0 Points
19 Posts
Jan 03, 2008 12:26 AM|LINK
hi everyone...
Iam new in Client side web
so I got this web page that includes 2 asp.net textboxes & a clear button....what I want here is when i click on the button to clear these 2 textboxes on the browser?
so how can I do that?
<%
<
username
password
</
thanks alot
Participant
807 Points
202 Posts
Jan 03, 2008 02:02 AM|LINK
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> <script type="text/javascript" language="javascript"> function ClearTextboxes() { document.getElementById('TextBox1').value = ''; document.getElementById('TextBox2').value = ''; } </script> </head> <body> <form id="form1" runat="server"> <div> username <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /> password <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br /> <asp:Button ID="ClearButton" runat="server" Text="Button" CausesValidation="false" OnClientClick="ClearTextboxes();" /> </div> </form> </body> </html>
All-Star
29935 Points
5821 Posts
Well you can add a reset html button....
or call document.forms[0].reset();
or
function clear(){ document.getElementById("<%= TextBox1.ClientID %>").value = ""; document.getElementById("<%= TextBox2.ClientID %>").value = ""; }
Eric
1394 Points
303 Posts
Jan 03, 2008 03:54 AM|LINK
Jan 03, 2008 04:01 AM|LINK
function clrCtrl() { document.getElementById('ctl00_ContentPlaceHolder1_TextBox1').value = ""; document.getElementById('ctl00_ContentPlaceHolder1_TextBox2').value = ""; } <asp:Button ID="ClearButton" runat="server" Style="position: static" Text="Button" OnClientClick="clrCtrl()" />
Jan 04, 2008 10:55 AM|LINK
thanks all for replying
well it worked fine with me...
but I got a question: I notice when I click on the button it goes to the server...I can see the Green loading bar down
so Can't I do this without going to the server?
82577 Points
15430 Posts
MVP
Jan 04, 2008 11:53 AM|LINK
Use a regular HTML button instead of an ASP:Button: <input type="button" value="Clear" onclick="JavaScript: clearTextBoxes();">
Or return false in the OnClientClick event of the ASP:Button: <asp:Button ... OnClientClick="clearTextBoxes(); return false;" />
NC...
Jan 08, 2008 11:33 PM|LINK
Member
73 Points
80 Posts
Mar 06, 2008 12:15 PM|LINK
NC01 Use a regular HTML button instead of an ASP:Button: <input type="button" value="Clear" onclick="JavaScript: clearTextBoxes();"> Or return false in the OnClientClick event of the ASP:Button: <asp:Button ... OnClientClick="clearTextBoxes(); return false;" /> NC...
Well, I try to use your code , but nothing happend
it gives me error in page
I belive your code is right, but I don't know what is wrong with my page
here is my code
<script type='text/javascript' language='javascript'>
function ClearTextboxes() {try { document.getElementById('ctl00_BodyContentPlaceHolder_txtSchoolNameEN').value = ''; document.getElementById('ctl00_BodyContentPlaceHolder_txtSchoolNameAR').value = ''; document.getElementById('ctl00_BodyContentPlaceHolder_drpGovernmentalDept').selectedIndex = 0; document.getElementById('ctl00_BodyContentPlaceHolder_txtNotes').value = ''; } catch(err) {var txt='Errot=>'+err.description;/*alert(txt);*/} } </script>
and I call the function like that
XX <IMG style="CURSOR: hand" id="ClearForm" onclick="javascript:clearTextBoxes();" src="../images/btncancel.gif" />
but I got that error
Object Expected and it refers to the line XX
any help please ????????
Mar 06, 2008 12:45 PM|LINK
Because your function is named ClearTextboxes() and you are calling clearTextBoxes(). Remember that JavaScript is case-sensitive. Try
<IMG style="CURSOR: hand" id="ClearForm" onclick="javascript:ClearTextBoxes();" src="../images/btncancel.gif" />
or change the function name to function clearTextBoxes() { ...
fahad11
0 Points
19 Posts
how to clear textboxes using javascript?
Jan 03, 2008 12:26 AM|LINK
hi everyone...
Iam new in Client side web
so I got this web page that includes 2 asp.net textboxes & a clear button....what I want here is when i click on the button to clear these 2 textboxes on the browser?
so how can I do that?
<%
@ Page Language="C#" MasterPageFile="~/MyMasterPage.master" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" Title="Untitled Page" %><
asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">username
<asp:TextBox ID="TextBox1" runat="server" Style="position: static"></asp:TextBox><br />password
<asp:TextBox ID="TextBox2" runat="server" Style="position: static"></asp:TextBox><br /> <asp:Button ID="ClearButton" runat="server" Style="position: static" Text="Button" /></
asp:Content>thanks alot
dcwhisen
Participant
807 Points
202 Posts
Re: how to clear textboxes using javascript?
Jan 03, 2008 02:02 AM|LINK
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" language="javascript">
function ClearTextboxes()
{
document.getElementById('TextBox1').value = '';
document.getElementById('TextBox2').value = '';
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
username
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
password
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
<asp:Button ID="ClearButton" runat="server" Text="Button" CausesValidation="false" OnClientClick="ClearTextboxes();" />
</div>
</form>
</body>
</html>
A1ien51
All-Star
29935 Points
5821 Posts
Re: how to clear textboxes using javascript?
Jan 03, 2008 02:02 AM|LINK
Well you can add a reset html button....
or call document.forms[0].reset();
or
function clear(){
document.getElementById("<%= TextBox1.ClientID %>").value = "";
document.getElementById("<%= TextBox2.ClientID %>").value = "";
}
Eric
windows_mss
Participant
1394 Points
303 Posts
Re: how to clear textboxes using javascript?
Jan 03, 2008 03:54 AM|LINK
NJoy Programming...
Blogging @ xploredotnet
windows_mss
Participant
1394 Points
303 Posts
Re: how to clear textboxes using javascript?
Jan 03, 2008 04:01 AM|LINK
function clrCtrl() { document.getElementById('ctl00_ContentPlaceHolder1_TextBox1').value = ""; document.getElementById('ctl00_ContentPlaceHolder1_TextBox2').value = ""; } <asp:Button ID="ClearButton" runat="server" Style="position: static" Text="Button" OnClientClick="clrCtrl()" />NJoy Programming...
Blogging @ xploredotnet
fahad11
0 Points
19 Posts
Re: how to clear textboxes using javascript?
Jan 04, 2008 10:55 AM|LINK
thanks all for replying
well it worked fine with me...
but I got a question: I notice when I click on the button it goes to the server...I can see the Green loading bar down
so Can't I do this without going to the server?
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: how to clear textboxes using javascript?
Jan 04, 2008 11:53 AM|LINK
Use a regular HTML button instead of an ASP:Button:
<input type="button" value="Clear" onclick="JavaScript: clearTextBoxes();">
Or return false in the OnClientClick event of the ASP:Button:
<asp:Button ... OnClientClick="clearTextBoxes(); return false;" />
NC...
fahad11
0 Points
19 Posts
Re: how to clear textboxes using javascript?
Jan 08, 2008 11:33 PM|LINK
thanks alot it worked fine with mead_dc
Member
73 Points
80 Posts
Re: how to clear textboxes using javascript?
Mar 06, 2008 12:15 PM|LINK
Well, I try to use your code , but nothing happend
it gives me error in page
I belive your code is right, but I don't know what is wrong with my page
here is my code
and I call the function like that
but I got that error
Object Expected and it refers to the line XX
any help please ????????
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: how to clear textboxes using javascript?
Mar 06, 2008 12:45 PM|LINK
Because your function is named ClearTextboxes() and you are calling clearTextBoxes(). Remember that JavaScript is case-sensitive. Try
<IMG style="CURSOR: hand" id="ClearForm" onclick="javascript:ClearTextBoxes();" src="../images/btncancel.gif" />
or change the function name to
function clearTextBoxes()
{
...
NC...