Client-Side Validation of asp:TextBox with Javascript

Discussion in 'ASP .Net' started by Matthew Wieder, Jul 23, 2003.

  1. Hi - I'm trying to do client-side validation of the text in a Asp.Net
    textbox control using javascript. My page has the following:
    <form id="Form1" method="post" runat="server" onsubmit="return
    validateName(this);">

    and

    <script language="JavaScript"><!--
    function validateName(theForm)
    {
    var reEval = new RegExp("[\\\/\:\*?\"\<\>|]", "i");

    blnEval = reEval.test(theForm.txtName.Value)

    if (blnEval)
    {
    alert("A Valid name must not contain any of the characters
    \\/:*?\"<>|");
    return false;
    }
    else
    {
    return true;
    }
    }

    //--></script>

    where txtName is the id in the <asp:TextBox tag. Problem is
    1) The theForm.txtName.Value always gives undefined as the value instead
    of the actual valus in the textbox.
    2) When the Javascript returns true, the page does not submit.

    Help anyone?
    thanks!
     
    Matthew Wieder, Jul 23, 2003
    #1
    1. Advertising

  2. Hi

    A quick glance
    theForm.txtName.value <---- value not Value

    --
    Best Regards
    Vidar Petursson
    ==============================
    Microsoft Internet Client & Controls MVP
    ==============================
    "Matthew Wieder" <> wrote in message
    news:...
    > Hi - I'm trying to do client-side validation of the text in a Asp.Net
    > textbox control using javascript. My page has the following:
    > <form id="Form1" method="post" runat="server" onsubmit="return
    > validateName(this);">
    >
    > and
    >
    > <script language="JavaScript"><!--
    > function validateName(theForm)
    > {
    > var reEval = new RegExp("[\\\/\:\*?\"\<\>|]", "i");
    >
    > blnEval = reEval.test(theForm.txtName.Value)
    >
    > if (blnEval)
    > {
    > alert("A Valid name must not contain any of the characters
    > \\/:*?\"<>|");
    > return false;
    > }
    > else
    > {
    > return true;
    > }
    > }
    >
    > //--></script>
    >
    > where txtName is the id in the <asp:TextBox tag. Problem is
    > 1) The theForm.txtName.Value always gives undefined as the value instead
    > of the actual valus in the textbox.
    > 2) When the Javascript returns true, the page does not submit.
    >
    > Help anyone?
    > thanks!
    >
     
    Vidar Petursson, Jul 23, 2003
    #2
    1. Advertising

  3. OK, you win points for the fast valid reply to part one of my problem -
    anybody know why the form wont submit?

    Vidar Petursson wrote:
    > Hi
    >
    > A quick glance
    > theForm.txtName.value <---- value not Value
    >
     
    Matthew Wieder, Jul 23, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    14
    Views:
    4,173
    Chad Z. Hower aka Kudzu
    Jan 30, 2004
  2. =?Utf-8?B?dmlkeWE=?=
    Replies:
    1
    Views:
    771
    Kevin Spencer
    Jun 2, 2005
  3. Boss302
    Replies:
    0
    Views:
    1,084
    Boss302
    Nov 21, 2006
  4. Bogdan
    Replies:
    2
    Views:
    678
    Bogdan
    Jun 9, 2008
  5. Christian Cambier

    client side validation with asp:TextBox ???

    Christian Cambier, Jul 14, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    534
    Christian Cambier
    Jul 14, 2008
Loading...

Share This Page