Hi,
I am crazy to fix the javascript bug for the past 2 days.
Here is the code:
[code]
ASPX code -------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML><HEAD><title>Test</title><meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"><meta content="C#" name="CODE_LANGUAGE"><meta content="JavaScript" name="vs_defaultClientScript"><meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"><script language="javascript">
function CheckInput()
{
var ft = document.all;
if(isEmpty(ft.lastname.value))
{
window.alert('Please Enter Last Name!');
ft.lastname.focus();
return false;
}
}
</script></HEAD><BODY><form id="contact" onsubmit="javascript:return CheckInput();" method="post" runat="server"><TABLE cellSpacing="0" cellPadding="0" width="100%" border="0"><TBODY><TR><td><asp:textbox id="lastname" Runat="server" CssClass="form" Wrap="False"></asp:textbox><asp:requiredfieldvalidator id="RequiredFieldValidatorLastName" runat="server" ErrorMessage="Please input last name!"
Display="None" ControlToValidate="lastname" EnableViewState="False"></asp:requiredfieldvalidator></td><td><asp:button id="btnSubmit" Runat="server" cssclass="button_3" text="Submit"></asp:button></td></TR></TBODY></TABLE></form></BODY></HTML>
C# code ------
protected System.Web.UI.WebControls.TextBox lastname;
protected System.Web.UI.WebControls.Button btnSubmit;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidatorLastName;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
}
}
#region Web Form
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnSubmit_Click(object sender, System.EventArgs e)
{
if(Page.IsValid)
{
}
}
[/code]
When I submit the form, there is no pop up dialog box to alert me.
The error message showed in IE6 is that "There must be an object".
It means it cannot locate id=lastname.
How should I fix it? Thanks for help.
bruce barker - 21 Apr 2004 20:52 GMT
your need to define isEmpty
-- bruce (sqlwork.com)
> Hi,
>
[quoted text clipped - 7 lines]
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
><HTML><HEAD><title>Test</title><meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"><meta content="C#" name="CODE_LANGUAGE"><meta
content="JavaScript" name="vs_defaultClientScript"><meta
content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema"><script language="javascript">
> function CheckInput()
> {
[quoted text clipped - 7 lines]
> }
> </script></HEAD><BODY><form id="contact" onsubmit="javascript:return CheckInput();" method="post" runat="server"><TABLE cellSpacing="0"
cellPadding="0" width="100%" border="0"><TBODY><TR><td><asp:textbox
id="lastname" Runat="server" CssClass="form"
Wrap="False"></asp:textbox><asp:requiredfieldvalidator
id="RequiredFieldValidatorLastName" runat="server" ErrorMessage="Please
input last name!"
> Display="None" ControlToValidate="lastname" EnableViewState="False"></asp:requiredfieldvalidator></td><td><asp:button
id="btnSubmit" Runat="server" cssclass="button_3"
text="Submit"></asp:button></td></TR></TBODY></TABLE></form></BODY></HTML>
> C# code ------
>
[quoted text clipped - 38 lines]
>
> How should I fix it? Thanks for help.
Shawn B. - 26 Apr 2004 20:12 GMT
Add the following code to your script tag:
function IsEmpty(value) {
if (value == '') {
return true;
}
return false;
}
Thanks,
Shawn
> Hi,
>
[quoted text clipped - 7 lines]
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
><HTML><HEAD><title>Test</title><meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"><meta content="C#" name="CODE_LANGUAGE"><meta
content="JavaScript" name="vs_defaultClientScript"><meta
content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema"><script language="javascript">
> function CheckInput()
> {
[quoted text clipped - 7 lines]
> }
> </script></HEAD><BODY><form id="contact" onsubmit="javascript:return CheckInput();" method="post" runat="server"><TABLE cellSpacing="0"
cellPadding="0" width="100%" border="0"><TBODY><TR><td><asp:textbox
id="lastname" Runat="server" CssClass="form"
Wrap="False"></asp:textbox><asp:requiredfieldvalidator
id="RequiredFieldValidatorLastName" runat="server" ErrorMessage="Please
input last name!"
> Display="None" ControlToValidate="lastname" EnableViewState="False"></asp:requiredfieldvalidator></td><td><asp:button
id="btnSubmit" Runat="server" cssclass="button_3"
text="Submit"></asp:button></td></TR></TBODY></TABLE></form></BODY></HTML>
> C# code ------
>
[quoted text clipped - 38 lines]
>
> How should I fix it? Thanks for help.