simple javascript form validation

simple javascript form validation

Post by V. Jenk » Sat, 06 Apr 2002 07:12:44



I have an html form set to runat="server"....I don't want to use the
validation controls, I'm simply trying to use a very basic client-side
javascript to validate the form fields, however, it's being completely
ignored and is not working.  I don't get errors, the validation just does
not happen!!  Could there be some sort of conflict with a form running at
the server?  Am I FORCED to use validation controls and make uncessary
round-trips to the server just to produce a script I can run on the clent
instead??

Am I just completely blind and missing something here?  Again, I get no
errors, the script just doesn't happen, nothing happens and the form submits
w/o validation (empty).

code:

<script language="javascript">
 function validateNewUsrForm()
 {
   var theForm = document.joinForm;
   var invalidChars = " /:,;";
   var badChar;

   if (theForm.FullName.value == "")
   {
     alert("Your full name is required.");
     theForm.FullName.focus();
     theForm.FullName.select();
     return false;
   }

   if ((theForm.Email.value == "") || (theForm.Email.indexOf('.') < 0) ||
(theForm.Email.indexOf('@') < 0))
   {
     alert("A valid e-mail address is required.");
     theForm.Email.focus();
     theForm.Email.select();
     return false;
   }

   for (em=0; em<=theForm.Email.length; em++)
   {
     badChar = invalidChars.charAt(em);
     if (theForm.Email.indexOf(badChar, 0) > -1)
     {
       alert("E-mail field cannot contain " + badChar + " character");
       return false;
     }
   }

   if (theForm.Category.selectedIndex == "")
   {
     alert("Please choose a category for yourself from the list.");
     return false;
   }

   if (theForm.Username.value == "")
   {
     alert("You must choose a Username.");
     theForm.Username.focus();
     theForm.Username.select();
     return false;
   }

   if (theForm.Password.value == "")
   {
     alert("You must choose a Password.");
     theForm.Password.focus();
     theForm.Password.select();
     return false;
   }
 }
</script>
</head>

<body bgcolor="#ffffff" background="../images/login_bkg.jpg"
onload="MM_preloadImages('../images/blockmenu/pfolio_button-over.gif','../im
ages/blockmenu/new_block_nav_20-pfolio_but.gif','../images/blockmenu/project
s_button-over.gif','../images/blockmenu/new_block_nav_20-projects_b.gif','..
/images/blockmenu/personal_button-over.gif','../images/blockmenu/new_block_n
av_20-personal_b.gif','../images/blockmenu/contact_button-over.gif','../imag
es/blockmenu/new_block_nav_20-contact_bu.gif','../images/blockmenu/avail_but
ton-over.gif','../images/blockmenu/new_block_nav_20-avail_butt.gif','../imag
es/blockmenu/about_button-over.gif','../images/blockmenu/new_block_nav_20-ab
out_butt.gif','../images/blockmenu/login_button-over.gif','../images/blockme
nu/new_block_nav_20-login_butt.gif','../images/blockmenu/news_button-over.gi
f','../images/blockmenu/new_block_nav_20-news_butto.gif','../images/blockmen
u/search_button-over.gif','../images/blockmenu/new_block_nav_20-search_but.g
if');" link=#c0c0c0 vlink=#c0c0c0 alink=#90ee90>
  <table width="700" border="0" height="500">
    <tr valign="top">
      <td width="156" height="396"><!-- #include
virtual="../includes/new_block_nav.inc" --></td>
      <td width="534" rowspan="2" align="right">
        <form name="joinForm" id="joinForm" method="post" onsubmit="return
validateNewUsrForm();" runat="server">
          <table width="250" border="0" cellpadding="5">
            <tr>
              <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
              <td colspan="2" class="bodyTxt"><b>Become a Member -
Scientifik.com</b></td>
            </tr>
            <tr>
              <td colspan="2" class="bodyTxt">
                Just fill out the short form below and an account will
automatically be created
                for you. Your Username and Password will be emailed to you
immediately
                afterwards.
              </td>
            </tr>
            <tr>
              <td width="40%" class="bodyTxt">
                <b>Full Name*</b>
              </td>
              <td width="60%" class="bodyTxt">
                <input type="text" id="FullName" name="FullName"
class="textBoxes" />
              </td>
            </tr>
            <tr>
              <td width="40%" class="bodyTxt">
                <b>Email*</b>
              </td>
              <td width="60%" class="bodyTxt">
                <input type="text" id="Email" name="Email" class="textBoxes"
/>
              </td>
            </tr>
            <tr>
              <td width="40%" class="bodyTxt">
                <b>Category</b>
              </td>
              <td width="60%" class="bodyTxt">
                <select name="Category" class="textBoxes">
                  <option value="" selected>(Choose From List)</option>
                  <option value="58968">Recruiting Agency          </option>
                  <option value="58969">Direct Employer            </option>
                  <option value="58970">Hiring Manager             </option>
                  <option value="58971">Private Recruiter          </option>
                  <option value="58972">Consultant                 </option>
                  <option value="58973">Other                      </option>
                </select>
              </td>
            </tr>
            <tr>
              <td width="40%" class="bodyTxt">
                <b>Company</b>
              </td>
              <td width="60%" class="bodyTxt">
                <asp:textbox id="Company" textmode="SingleLine"
cssclass="textBoxes" runat="server"/>
              </td>
            </tr>
            <tr>
              <td width="40%" class="bodyTxt">
                <b>City</b>
              </td>
              <td width="60%" class="bodyTxt">
                <asp:textbox id="City" textmode="SingleLine"
cssclass="textBoxes" runat="server"/>
              </td>
            </tr>
            <tr>
              <td width="40%" class="bodyTxt">
                <b>State</b>
              </td>
              <td width="60%" class="bodyTxt">
                <asp:textbox id="State" width="25" textmode="SingleLine"
cssclass="textBoxes" runat="server"/>
              </td>
            </tr>
            <tr>
              <td width="40%" class="bodyTxt">
                <b>Your Interest</b>
              </td>
              <td width="60%" class="bodyTxt">
                <asp:textbox id="Interest" textmode="MultiLine" rows="4"
columns="25" cssclass="textBoxes" runat="server"/>
              </td>
            </tr>
            <tr>
              <td colspan="2"><hr width="75%" noshade ></td>
            </tr>
            <tr>
              <td width="40%" class="bodyTxt">
                <b>Username*</b>
              </td>
              <td width="60%" class="bodyTxt">
                <input type="text" name="Username" id="Username"
class="textBoxes" />
              </td>
            </tr>
            <tr>
              <td width="40%" class="bodyTxt">
                <b>Password*</b>
              </td>
              <td width="60%" class="bodyTxt">
                <input type="text" name="Password" id="Password"
class="textBoxes" />
              </td>
            </tr>
            <tr>
              <td colspan="2" align="right" class="bodyTxt">
                <b><asp:linkbutton id="joinSubmit" onclick="LogNewUsr"
text="Join Now" runat="server"/></b>
              </td>
            </tr>
          </table>
        </form>

 
 
 

simple javascript form validation

Post by Joe Kin » Sat, 06 Apr 2002 08:20:11


The reason it is not working is because the asp:LinkButton uses
href="javascript: __doPostBack()" in the generated HTML <a> tag to post the
form, it doesn't use the conventional HTML POST tied to the FORM tag.  Your
onsubmit never fires.

Try this.

remove:

onsubmit="return validateNewUsrForm();"

Then, in CodeBehind or from a Server-Side script block (C#), in the
Page_Load event:

joinButton.Attributes.Add("onclick", "return validateNewUsrForm();");

I believe this will do what you are after.  It will create a client-side
"onclick" event for your hyperlink LinkButton.  This fires prior to the
href="__doPostBack" and can conditionally cancel href all together.

Regards,

Joseph King
Coalesys, Inc.
http://www.coalesys.com/
ASP.NET Navigation Toolkit
Microsoft Tech-Ed 2002, booth #739

"V. Jenks" <s...@scientifik.com> wrote in message

news:O7V31VC3BHA.2684@tkmsftngp04...
> I have an html form set to runat="server"....I don't want to use the
> validation controls, I'm simply trying to use a very basic client-side
> javascript to validate the form fields, however, it's being completely
> ignored and is not working.  I don't get errors, the validation just does
> not happen!!  Could there be some sort of conflict with a form running at
> the server?  Am I FORCED to use validation controls and make uncessary
> round-trips to the server just to produce a script I can run on the clent
> instead??

> Am I just completely blind and missing something here?  Again, I get no
> errors, the script just doesn't happen, nothing happens and the form
submits
> w/o validation (empty).

> code:

> <script language="javascript">
>  function validateNewUsrForm()
>  {
>    var theForm = document.joinForm;
>    var invalidChars = " /:,;";
>    var badChar;

>    if (theForm.FullName.value == "")
>    {
>      alert("Your full name is required.");
>      theForm.FullName.focus();
>      theForm.FullName.select();
>      return false;
>    }

>    if ((theForm.Email.value == "") || (theForm.Email.indexOf('.') < 0) ||
> (theForm.Email.indexOf('@') < 0))
>    {
>      alert("A valid e-mail address is required.");
>      theForm.Email.focus();
>      theForm.Email.select();
>      return false;
>    }

>    for (em=0; em<=theForm.Email.length; em++)
>    {
>      badChar = invalidChars.charAt(em);
>      if (theForm.Email.indexOf(badChar, 0) > -1)
>      {
>        alert("E-mail field cannot contain " + badChar + " character");
>        return false;
>      }
>    }

>    if (theForm.Category.selectedIndex == "")
>    {
>      alert("Please choose a category for yourself from the list.");
>      return false;
>    }

>    if (theForm.Username.value == "")
>    {
>      alert("You must choose a Username.");
>      theForm.Username.focus();
>      theForm.Username.select();
>      return false;
>    }

>    if (theForm.Password.value == "")
>    {
>      alert("You must choose a Password.");
>      theForm.Password.focus();
>      theForm.Password.select();
>      return false;
>    }
>  }
> </script>
> </head>

> <body bgcolor="#ffffff" background="../images/login_bkg.jpg"

onload="MM_preloadImages('../images/blockmenu/pfolio_button-over.gif','../im

ages/blockmenu/new_block_nav_20-pfolio_but.gif','../images/blockmenu/project

s_button-over.gif','../images/blockmenu/new_block_nav_20-projects_b.gif','..

/images/blockmenu/personal_button-over.gif','../images/blockmenu/new_block_n

av_20-personal_b.gif','../images/blockmenu/contact_button-over.gif','../imag

es/blockmenu/new_block_nav_20-contact_bu.gif','../images/blockmenu/avail_but

ton-over.gif','../images/blockmenu/new_block_nav_20-avail_butt.gif','../imag

es/blockmenu/about_button-over.gif','../images/blockmenu/new_block_nav_20-ab

out_butt.gif','../images/blockmenu/login_button-over.gif','../images/blockme

nu/new_block_nav_20-login_butt.gif','../images/blockmenu/news_button-over.gi

f','../images/blockmenu/new_block_nav_20-news_butto.gif','../images/blockmen


u/search_button-over.gif','../images/blockmenu/new_block_nav_20-search_but.g

- Show quoted text -

> if');" link=#c0c0c0 vlink=#c0c0c0 alink=#90ee90>
>   <table width="700" border="0" height="500">
>     <tr valign="top">
>       <td width="156" height="396"><!-- #include
> virtual="../includes/new_block_nav.inc" --></td>
>       <td width="534" rowspan="2" align="right">
>         <form name="joinForm" id="joinForm" method="post" onsubmit="return
> validateNewUsrForm();" runat="server">
>           <table width="250" border="0" cellpadding="5">
>             <tr>
>               <td colspan="2">&nbsp;</td>
>             </tr>
>             <tr>
>               <td colspan="2" class="bodyTxt"><b>Become a Member -
> Scientifik.com</b></td>
>             </tr>
>             <tr>
>               <td colspan="2" class="bodyTxt">
>                 Just fill out the short form below and an account will
> automatically be created
>                 for you. Your Username and Password will be emailed to you
> immediately
>                 afterwards.
>               </td>
>             </tr>
>             <tr>
>               <td width="40%" class="bodyTxt">
>                 <b>Full Name*</b>
>               </td>
>               <td width="60%" class="bodyTxt">
>                 <input type="text" id="FullName" name="FullName"
> class="textBoxes" />
>               </td>
>             </tr>
>             <tr>
>               <td width="40%" class="bodyTxt">
>                 <b>Email*</b>
>               </td>
>               <td width="60%" class="bodyTxt">
>                 <input type="text" id="Email" name="Email"
class="textBoxes"
> />
>               </td>
>             </tr>
>             <tr>
>               <td width="40%" class="bodyTxt">
>                 <b>Category</b>
>               </td>
>               <td width="60%" class="bodyTxt">
>                 <select name="Category" class="textBoxes">
>                   <option value="" selected>(Choose From List)</option>
>                   <option value="58968">Recruiting Agency
</option>
>                   <option value="58969">Direct Employer
</option>
>                   <option value="58970">Hiring Manager
</option>
>                   <option value="58971">Private Recruiter
</option>
>                   <option value="58972">Consultant
</option>
>                   <option value="58973">Other
</option>
>                 </select>
>               </td>
>             </tr>
>             <tr>
>               <td width="40%" class="bodyTxt">
>                 <b>Company</b>
>               </td>
>               <td width="60%" class="bodyTxt">
>                 <asp:textbox id="Company" textmode="SingleLine"
> cssclass="textBoxes" runat="server"/>
>               </td>
>             </tr>
>             <tr>
>               <td width="40%" class="bodyTxt">
>                 <b>City</b>
>               </td>
>               <td width="60%" class="bodyTxt">
>                 <asp:textbox id="City" textmode="SingleLine"
> cssclass="textBoxes" runat="server"/>
>               </td>
>             </tr>
>             <tr>
>               <td width="40%" class="bodyTxt">
>                 <b>State</b>
>               </td>
>               <td width="60%" class="bodyTxt">
>                 <asp:textbox id="State" width="25" textmode="SingleLine"
> cssclass="textBoxes" runat="server"/>
>               </td>
>             </tr>
>             <tr>
>               <td width="40%" class="bodyTxt">
>                 <b>Your Interest</b>
>               </td>
>               <td width="60%" class="bodyTxt">
>                 <asp:textbox id="Interest" textmode="MultiLine" rows="4"
> columns="25" cssclass="textBoxes" runat="server"/>
>               </td>
>             </tr>
>             <tr>
>               <td colspan="2"><hr width="75%" noshade ></td>
>             </tr>
>             <tr>
>               <td width="40%" class="bodyTxt">
>                 <b>Username*</b>
>               </td>
>               <td width="60%" class="bodyTxt">
>                 <input type="text" name="Username" id="Username"
> class="textBoxes" />
>               </td>
>             </tr>
>             <tr>
>               <td width="40%" class="bodyTxt">
>                 <b>Password*</b>
>               </td>
>               <td width="60%" class="bodyTxt">
>                 <input type="text" name="Password" id="Password"
> class="textBoxes" />
>               </td>
>             </tr>
>             <tr>
>               <td colspan="2" align="right" class="bodyTxt">
>                 <b><asp:linkbutton id="joinSubmit" onclick="LogNewUsr"
> text="Join Now" runat="server"/></b>
>               </td>
>             </tr>
>           </table>
>         </form>


 
 
 

simple javascript form validation

Post by V. Jenk » Sat, 06 Apr 2002 08:47:18


That worked great, thanks very much.  I absolutely love asp.net after
programming with asp for several years but I will say this; I seriously hope
they overhaul and improve the server controls on the next iteration of
asp.net!

Thanks again!

"Joe King" <jk...@coalesys.spambegone.com> wrote in message

news:eXc8m8C3BHA.376@tkmsftngp02...
> The reason it is not working is because the asp:LinkButton uses
> href="javascript: __doPostBack()" in the generated HTML <a> tag to post
the
> form, it doesn't use the conventional HTML POST tied to the FORM tag.
Your
> onsubmit never fires.

> Try this.

> remove:

> onsubmit="return validateNewUsrForm();"

> Then, in CodeBehind or from a Server-Side script block (C#), in the
> Page_Load event:

> joinButton.Attributes.Add("onclick", "return validateNewUsrForm();");

> I believe this will do what you are after.  It will create a client-side
> "onclick" event for your hyperlink LinkButton.  This fires prior to the
> href="__doPostBack" and can conditionally cancel href all together.

> Regards,

> Joseph King
> Coalesys, Inc.
> http://www.coalesys.com/
> ASP.NET Navigation Toolkit
> Microsoft Tech-Ed 2002, booth #739

> "V. Jenks" <s...@scientifik.com> wrote in message
> news:O7V31VC3BHA.2684@tkmsftngp04...
> > I have an html form set to runat="server"....I don't want to use the
> > validation controls, I'm simply trying to use a very basic client-side
> > javascript to validate the form fields, however, it's being completely
> > ignored and is not working.  I don't get errors, the validation just
does
> > not happen!!  Could there be some sort of conflict with a form running
at
> > the server?  Am I FORCED to use validation controls and make uncessary
> > round-trips to the server just to produce a script I can run on the
clent
> > instead??

> > Am I just completely blind and missing something here?  Again, I get no
> > errors, the script just doesn't happen, nothing happens and the form
> submits
> > w/o validation (empty).

> > code:

> > <script language="javascript">
> >  function validateNewUsrForm()
> >  {
> >    var theForm = document.joinForm;
> >    var invalidChars = " /:,;";
> >    var badChar;

> >    if (theForm.FullName.value == "")
> >    {
> >      alert("Your full name is required.");
> >      theForm.FullName.focus();
> >      theForm.FullName.select();
> >      return false;
> >    }

> >    if ((theForm.Email.value == "") || (theForm.Email.indexOf('.') < 0)
||
> > (theForm.Email.indexOf('@') < 0))
> >    {
> >      alert("A valid e-mail address is required.");
> >      theForm.Email.focus();
> >      theForm.Email.select();
> >      return false;
> >    }

> >    for (em=0; em<=theForm.Email.length; em++)
> >    {
> >      badChar = invalidChars.charAt(em);
> >      if (theForm.Email.indexOf(badChar, 0) > -1)
> >      {
> >        alert("E-mail field cannot contain " + badChar + " character");
> >        return false;
> >      }
> >    }

> >    if (theForm.Category.selectedIndex == "")
> >    {
> >      alert("Please choose a category for yourself from the list.");
> >      return false;
> >    }

> >    if (theForm.Username.value == "")
> >    {
> >      alert("You must choose a Username.");
> >      theForm.Username.focus();
> >      theForm.Username.select();
> >      return false;
> >    }

> >    if (theForm.Password.value == "")
> >    {
> >      alert("You must choose a Password.");
> >      theForm.Password.focus();
> >      theForm.Password.select();
> >      return false;
> >    }
> >  }
> > </script>
> > </head>

> > <body bgcolor="#ffffff" background="../images/login_bkg.jpg"

onload="MM_preloadImages('../images/blockmenu/pfolio_button-over.gif','../im

ages/blockmenu/new_block_nav_20-pfolio_but.gif','../images/blockmenu/project

s_button-over.gif','../images/blockmenu/new_block_nav_20-projects_b.gif','..

/images/blockmenu/personal_button-over.gif','../images/blockmenu/new_block_n

av_20-personal_b.gif','../images/blockmenu/contact_button-over.gif','../imag

es/blockmenu/new_block_nav_20-contact_bu.gif','../images/blockmenu/avail_but

ton-over.gif','../images/blockmenu/new_block_nav_20-avail_butt.gif','../imag

es/blockmenu/about_button-over.gif','../images/blockmenu/new_block_nav_20-ab

out_butt.gif','../images/blockmenu/login_button-over.gif','../images/blockme

nu/new_block_nav_20-login_butt.gif','../images/blockmenu/news_button-over.gi

f','../images/blockmenu/new_block_nav_20-news_butto.gif','../images/blockmen

u/search_button-over.gif','../images/blockmenu/new_block_nav_20-search_but.g

- Show quoted text -

> > if');" link=#c0c0c0 vlink=#c0c0c0 alink=#90ee90>
> >   <table width="700" border="0" height="500">
> >     <tr valign="top">
> >       <td width="156" height="396"><!-- #include
> > virtual="../includes/new_block_nav.inc" --></td>
> >       <td width="534" rowspan="2" align="right">
> >         <form name="joinForm" id="joinForm" method="post"
onsubmit="return
> > validateNewUsrForm();" runat="server">
> >           <table width="250" border="0" cellpadding="5">
> >             <tr>
> >               <td colspan="2">&nbsp;</td>
> >             </tr>
> >             <tr>
> >               <td colspan="2" class="bodyTxt"><b>Become a Member -
> > Scientifik.com</b></td>
> >             </tr>
> >             <tr>
> >               <td colspan="2" class="bodyTxt">
> >                 Just fill out the short form below and an account will
> > automatically be created
> >                 for you. Your Username and Password will be emailed to
you
> > immediately
> >                 afterwards.
> >               </td>
> >             </tr>
> >             <tr>
> >               <td width="40%" class="bodyTxt">
> >                 <b>Full Name*</b>
> >               </td>
> >               <td width="60%" class="bodyTxt">
> >                 <input type="text" id="FullName" name="FullName"
> > class="textBoxes" />
> >               </td>
> >             </tr>
> >             <tr>
> >               <td width="40%" class="bodyTxt">
> >                 <b>Email*</b>
> >               </td>
> >               <td width="60%" class="bodyTxt">
> >                 <input type="text" id="Email" name="Email"
> class="textBoxes"
> > />
> >               </td>
> >             </tr>
> >             <tr>
> >               <td width="40%" class="bodyTxt">
> >                 <b>Category</b>
> >               </td>
> >               <td width="60%" class="bodyTxt">
> >                 <select name="Category" class="textBoxes">
> >                   <option value="" selected>(Choose From List)</option>
> >                   <option value="58968">Recruiting Agency
> </option>
> >                   <option value="58969">Direct Employer
> </option>
> >                   <option value="58970">Hiring Manager
> </option>
> >                   <option value="58971">Private Recruiter
> </option>
> >                   <option value="58972">Consultant
> </option>
> >                   <option value="58973">Other
> </option>
> >                 </select>
> >               </td>
> >             </tr>
> >             <tr>
> >               <td width="40%" class="bodyTxt">
> >                 <b>Company</b>
> >               </td>
> >               <td width="60%" class="bodyTxt">
> >                 <asp:textbox id="Company" textmode="SingleLine"
> > cssclass="textBoxes" runat="server"/>
> >               </td>
> >             </tr>
> >             <tr>
> >               <td width="40%" class="bodyTxt">
> >                 <b>City</b>
> >               </td>
> >               <td width="60%" class="bodyTxt">
> >                 <asp:textbox id="City" textmode="SingleLine"
> > cssclass="textBoxes" runat="server"/>
> >               </td>
> >             </tr>
> >             <tr>
> >               <td width="40%" class="bodyTxt">
> >                 <b>State</b>
> >               </td>
> >               <td width="60%" class="bodyTxt">
> >                 <asp:textbox id="State" width="25" textmode="SingleLine"
> > cssclass="textBoxes" runat="server"/>
> >               </td>
> >             </tr>
> >             <tr>
> >               <td width="40%" class="bodyTxt">
> >                 <b>Your Interest</b>
> >               </td>
> >               <td width="60%" class="bodyTxt">
> >                 <asp:textbox id="Interest" textmode="MultiLine" rows="4"
> > columns="25" cssclass="textBoxes" runat="server"/>
> >               </td>
> >             </tr>
> >             <tr>
> >               <td colspan="2"><hr width="75%" noshade ></td>
> >             </tr>
> >             <tr>
> >               <td width="40%" class="bodyTxt">
> >                 <b>Username*</b>
> >               </td>
> >               <td width="60%" class="bodyTxt">
> >                 <input type="text" name="Username" id="Username"
> > class="textBoxes" />
> >               </td>
> >             </tr>
> >             <tr>
> >               <td width="40%" class="bodyTxt">
> >                 <b>Password*</b>
> >               </td>
> >               <td width="60%" class="bodyTxt">
> >                 <input type="text" name="Password" id="Password"
> > class="textBoxes" />
> >               </td>
> >             </tr>
> >             <tr>
> >               <td colspan="2" align="right" class="bodyTxt">
> >                 <b><asp:linkbutton id="joinSubmit" onclick="LogNewUsr"
> > text="Join Now" runat="server"/></b>
> >               </td>
> >             </tr>
> >           </table>
> >         </form>

 
 
 

simple javascript form validation

Post by V. Jenk » Sat, 06 Apr 2002 12:12:41


I built a simple login page.  When the user logs in a cookie is created, if
the login fails the cookie is NOT created.  I then use the cookie as a test
to see if that person is logged in and to see whether or not they are
allowed to view the subsequent pages below the login page.

In classic asp I would have simply tested the cookie to see if it had keys
or not.  Worked great in asp, however, in asp.net if you test for keys in a
cookie that does not exist you get this error:

Object reference not set to an instance of an object.

How can I test for the existence of this cookie so I do not get this error?
If I cannot, how can I best duplicate the functionality described above?

Thanks everyone!

-v

"V. Jenks" <s...@scientifik.com> wrote in message

news:O7V31VC3BHA.2684@tkmsftngp04...
> I have an html form set to runat="server"....I don't want to use the
> validation controls, I'm simply trying to use a very basic client-side
> javascript to validate the form fields, however, it's being completely
> ignored and is not working.  I don't get errors, the validation just does
> not happen!!  Could there be some sort of conflict with a form running at
> the server?  Am I FORCED to use validation controls and make uncessary
> round-trips to the server just to produce a script I can run on the clent
> instead??

> Am I just completely blind and missing something here?  Again, I get no
> errors, the script just doesn't happen, nothing happens and the form
submits
> w/o validation (empty).

> code:

> <script language="javascript">
>  function validateNewUsrForm()
>  {
>    var theForm = document.joinForm;
>    var invalidChars = " /:,;";
>    var badChar;

>    if (theForm.FullName.value == "")
>    {
>      alert("Your full name is required.");
>      theForm.FullName.focus();
>      theForm.FullName.select();
>      return false;
>    }

>    if ((theForm.Email.value == "") || (theForm.Email.indexOf('.') < 0) ||
> (theForm.Email.indexOf('@') < 0))
>    {
>      alert("A valid e-mail address is required.");
>      theForm.Email.focus();
>      theForm.Email.select();
>      return false;
>    }

>    for (em=0; em<=theForm.Email.length; em++)
>    {
>      badChar = invalidChars.charAt(em);
>      if (theForm.Email.indexOf(badChar, 0) > -1)
>      {
>        alert("E-mail field cannot contain " + badChar + " character");
>        return false;
>      }
>    }

>    if (theForm.Category.selectedIndex == "")
>    {
>      alert("Please choose a category for yourself from the list.");
>      return false;
>    }

>    if (theForm.Username.value == "")
>    {
>      alert("You must choose a Username.");
>      theForm.Username.focus();
>      theForm.Username.select();
>      return false;
>    }

>    if (theForm.Password.value == "")
>    {
>      alert("You must choose a Password.");
>      theForm.Password.focus();
>      theForm.Password.select();
>      return false;
>    }
>  }
> </script>
> </head>

> <body bgcolor="#ffffff" background="../images/login_bkg.jpg"

onload="MM_preloadImages('../images/blockmenu/pfolio_button-over.gif','../im

ages/blockmenu/new_block_nav_20-pfolio_but.gif','../images/blockmenu/project

s_button-over.gif','../images/blockmenu/new_block_nav_20-projects_b.gif','..

/images/blockmenu/personal_button-over.gif','../images/blockmenu/new_block_n

av_20-personal_b.gif','../images/blockmenu/contact_button-over.gif','../imag

es/blockmenu/new_block_nav_20-contact_bu.gif','../images/blockmenu/avail_but

ton-over.gif','../images/blockmenu/new_block_nav_20-avail_butt.gif','../imag

es/blockmenu/about_button-over.gif','../images/blockmenu/new_block_nav_20-ab

out_butt.gif','../images/blockmenu/login_button-over.gif','../images/blockme

nu/new_block_nav_20-login_butt.gif','../images/blockmenu/news_button-over.gi

f','../images/blockmenu/new_block_nav_20-news_butto.gif','../images/blockmen

u/search_button-over.gif','../images/blockmenu/new_block_nav_20-search_but.g

- Show quoted text -

> if');" link=#c0c0c0 vlink=#c0c0c0 alink=#90ee90>
>   <table width="700" border="0" height="500">
>     <tr valign="top">
>       <td width="156" height="396"><!-- #include
> virtual="../includes/new_block_nav.inc" --></td>
>       <td width="534" rowspan="2" align="right">
>         <form name="joinForm" id="joinForm" method="post" onsubmit="return
> validateNewUsrForm();" runat="server">
>           <table width="250" border="0" cellpadding="5">
>             <tr>
>               <td colspan="2">&nbsp;</td>
>             </tr>
>             <tr>
>               <td colspan="2" class="bodyTxt"><b>Become a Member -
> Scientifik.com</b></td>
>             </tr>
>             <tr>
>               <td colspan="2" class="bodyTxt">
>                 Just fill out the short form below and an account will
> automatically be created
>                 for you. Your Username and Password will be emailed to you
> immediately
>                 afterwards.
>               </td>
>             </tr>
>             <tr>
>               <td width="40%" class="bodyTxt">
>                 <b>Full Name*</b>
>               </td>
>               <td width="60%" class="bodyTxt">
>                 <input type="text" id="FullName" name="FullName"
> class="textBoxes" />
>               </td>
>             </tr>
>             <tr>
>               <td width="40%" class="bodyTxt">
>                 <b>Email*</b>
>               </td>
>               <td width="60%" class="bodyTxt">
>                 <input type="text" id="Email" name="Email"
class="textBoxes"
> />
>               </td>
>             </tr>
>             <tr>
>               <td width="40%" class="bodyTxt">
>                 <b>Category</b>
>               </td>
>               <td width="60%" class="bodyTxt">
>                 <select name="Category" class="textBoxes">
>                   <option value="" selected>(Choose From List)</option>
>                   <option value="58968">Recruiting Agency
</option>
>                   <option value="58969">Direct Employer
</option>
>                   <option value="58970">Hiring Manager
</option>
>                   <option value="58971">Private Recruiter
</option>
>                   <option value="58972">Consultant
</option>
>                   <option value="58973">Other
</option>
>                 </select>
>               </td>
>             </tr>
>             <tr>
>               <td width="40%" class="bodyTxt">
>                 <b>Company</b>
>               </td>
>               <td width="60%" class="bodyTxt">
>                 <asp:textbox id="Company" textmode="SingleLine"
> cssclass="textBoxes" runat="server"/>
>               </td>
>             </tr>
>             <tr>
>               <td width="40%" class="bodyTxt">
>                 <b>City</b>
>               </td>
>               <td width="60%" class="bodyTxt">
>                 <asp:textbox id="City" textmode="SingleLine"
> cssclass="textBoxes" runat="server"/>
>               </td>
>             </tr>
>             <tr>
>               <td width="40%" class="bodyTxt">
>                 <b>State</b>
>               </td>
>               <td width="60%" class="bodyTxt">
>                 <asp:textbox id="State" width="25" textmode="SingleLine"
> cssclass="textBoxes" runat="server"/>
>               </td>
>             </tr>
>             <tr>
>               <td width="40%" class="bodyTxt">
>                 <b>Your Interest</b>
>               </td>
>               <td width="60%" class="bodyTxt">
>                 <asp:textbox id="Interest" textmode="MultiLine" rows="4"
> columns="25" cssclass="textBoxes" runat="server"/>
>               </td>
>             </tr>
>             <tr>
>               <td colspan="2"><hr width="75%" noshade ></td>
>             </tr>
>             <tr>
>               <td width="40%" class="bodyTxt">
>                 <b>Username*</b>
>               </td>
>               <td width="60%" class="bodyTxt">
>                 <input type="text" name="Username" id="Username"
> class="textBoxes" />
>               </td>
>             </tr>
>             <tr>
>               <td width="40%" class="bodyTxt">
>                 <b>Password*</b>
>               </td>
>               <td width="60%" class="bodyTxt">
>                 <input type="text" name="Password" id="Password"
> class="textBoxes" />
>               </td>
>             </tr>
>             <tr>
>               <td colspan="2" align="right" class="bodyTxt">
>                 <b><asp:linkbutton id="joinSubmit" onclick="LogNewUsr"
> text="Join Now" runat="server"/></b>
>               </td>
>             </tr>
>           </table>
>         </form>

 
 
 

simple javascript form validation

Post by Doug Thew » Sat, 06 Apr 2002 12:19:33


Use "Is Nothing" (VB.NET) as a comparator in an If statement to determine if
the cookie is null before trying to drill into it.

--
Doug Thews
Director, Software Development
Data Return Corp.

"V. Jenks" <s...@scientifik.com> wrote in message

news:ui87d9E3BHA.2564@tkmsftngp03...
> I built a simple login page.  When the user logs in a cookie is created,
if
> the login fails the cookie is NOT created.  I then use the cookie as a
test
> to see if that person is logged in and to see whether or not they are
> allowed to view the subsequent pages below the login page.

> In classic asp I would have simply tested the cookie to see if it had keys
> or not.  Worked great in asp, however, in asp.net if you test for keys in
a
> cookie that does not exist you get this error:

> Object reference not set to an instance of an object.

> How can I test for the existence of this cookie so I do not get this
error?
> If I cannot, how can I best duplicate the functionality described above?

> Thanks everyone!

> -v

> "V. Jenks" <s...@scientifik.com> wrote in message
> news:O7V31VC3BHA.2684@tkmsftngp04...
> > I have an html form set to runat="server"....I don't want to use the
> > validation controls, I'm simply trying to use a very basic client-side
> > javascript to validate the form fields, however, it's being completely
> > ignored and is not working.  I don't get errors, the validation just
does
> > not happen!!  Could there be some sort of conflict with a form running
at
> > the server?  Am I FORCED to use validation controls and make uncessary
> > round-trips to the server just to produce a script I can run on the
clent
> > instead??

> > Am I just completely blind and missing something here?  Again, I get no
> > errors, the script just doesn't happen, nothing happens and the form
> submits
> > w/o validation (empty).

> > code:

> > <script language="javascript">
> >  function validateNewUsrForm()
> >  {
> >    var theForm = document.joinForm;
> >    var invalidChars = " /:,;";
> >    var badChar;

> >    if (theForm.FullName.value == "")
> >    {
> >      alert("Your full name is required.");
> >      theForm.FullName.focus();
> >      theForm.FullName.select();
> >      return false;
> >    }

> >    if ((theForm.Email.value == "") || (theForm.Email.indexOf('.') < 0)
||
> > (theForm.Email.indexOf('@') < 0))
> >    {
> >      alert("A valid e-mail address is required.");
> >      theForm.Email.focus();
> >      theForm.Email.select();
> >      return false;
> >    }

> >    for (em=0; em<=theForm.Email.length; em++)
> >    {
> >      badChar = invalidChars.charAt(em);
> >      if (theForm.Email.indexOf(badChar, 0) > -1)
> >      {
> >        alert("E-mail field cannot contain " + badChar + " character");
> >        return false;
> >      }
> >    }

> >    if (theForm.Category.selectedIndex == "")
> >    {
> >      alert("Please choose a category for yourself from the list.");
> >      return false;
> >    }

> >    if (theForm.Username.value == "")
> >    {
> >      alert("You must choose a Username.");
> >      theForm.Username.focus();
> >      theForm.Username.select();
> >      return false;
> >    }

> >    if (theForm.Password.value == "")
> >    {
> >      alert("You must choose a Password.");
> >      theForm.Password.focus();
> >      theForm.Password.select();
> >      return false;
> >    }
> >  }
> > </script>
> > </head>

> > <body bgcolor="#ffffff" background="../images/login_bkg.jpg"

onload="MM_preloadImages('../images/blockmenu/pfolio_button-over.gif','../im

ages/blockmenu/new_block_nav_20-pfolio_but.gif','../images/blockmenu/project

s_button-over.gif','../images/blockmenu/new_block_nav_20-projects_b.gif','..

/images/blockmenu/personal_button-over.gif','../images/blockmenu/new_block_n

av_20-personal_b.gif','../images/blockmenu/contact_button-over.gif','../imag

es/blockmenu/new_block_nav_20-contact_bu.gif','../images/blockmenu/avail_but

ton-over.gif','../images/blockmenu/new_block_nav_20-avail_butt.gif','../imag

es/blockmenu/about_button-over.gif','../images/blockmenu/new_block_nav_20-ab

out_butt.gif','../images/blockmenu/login_button-over.gif','../images/blockme

nu/new_block_nav_20-login_butt.gif','../images/blockmenu/news_button-over.gi

f','../images/blockmenu/new_block_nav_20-news_butto.gif','../images/blockmen

u/search_button-over.gif','../images/blockmenu/new_block_nav_20-search_but.g

- Show quoted text -

> > if');" link=#c0c0c0 vlink=#c0c0c0 alink=#90ee90>
> >   <table width="700" border="0" height="500">
> >     <tr valign="top">
> >       <td width="156" height="396"><!-- #include
> > virtual="../includes/new_block_nav.inc" --></td>
> >       <td width="534" rowspan="2" align="right">
> >         <form name="joinForm" id="joinForm" method="post"
onsubmit="return
> > validateNewUsrForm();" runat="server">
> >           <table width="250" border="0" cellpadding="5">
> >             <tr>
> >               <td colspan="2">&nbsp;</td>
> >             </tr>
> >             <tr>
> >               <td colspan="2" class="bodyTxt"><b>Become a Member -
> > Scientifik.com</b></td>
> >             </tr>
> >             <tr>
> >               <td colspan="2" class="bodyTxt">
> >                 Just fill out the short form below and an account will
> > automatically be created
> >                 for you. Your Username and Password will be emailed to
you
> > immediately
> >                 afterwards.
> >               </td>
> >             </tr>
> >             <tr>
> >               <td width="40%" class="bodyTxt">
> >                 <b>Full Name*</b>
> >               </td>
> >               <td width="60%" class="bodyTxt">
> >                 <input type="text" id="FullName" name="FullName"
> > class="textBoxes" />
> >               </td>
> >             </tr>
> >             <tr>
> >               <td width="40%" class="bodyTxt">
> >                 <b>Email*</b>
> >               </td>
> >               <td width="60%" class="bodyTxt">
> >                 <input type="text" id="Email" name="Email"
> class="textBoxes"
> > />
> >               </td>
> >             </tr>
> >             <tr>
> >               <td width="40%" class="bodyTxt">
> >                 <b>Category</b>
> >               </td>
> >               <td width="60%" class="bodyTxt">
> >                 <select name="Category" class="textBoxes">
> >                   <option value="" selected>(Choose From List)</option>
> >                   <option value="58968">Recruiting Agency
> </option>
> >                   <option value="58969">Direct Employer
> </option>
> >                   <option value="58970">Hiring Manager
> </option>
> >                   <option value="58971">Private Recruiter
> </option>
> >                   <option value="58972">Consultant
> </option>
> >                   <option value="58973">Other
> </option>
> >                 </select>
> >               </td>
> >             </tr>
> >             <tr>
> >               <td width="40%" class="bodyTxt">
> >                 <b>Company</b>
> >               </td>
> >               <td width="60%" class="bodyTxt">
> >                 <asp:textbox id="Company" textmode="SingleLine"
> > cssclass="textBoxes" runat="server"/>
> >               </td>
> >             </tr>
> >             <tr>
> >               <td width="40%" class="bodyTxt">
> >                 <b>City</b>
> >               </td>
> >               <td width="60%" class="bodyTxt">
> >                 <asp:textbox id="City" textmode="SingleLine"
> > cssclass="textBoxes" runat="server"/>
> >               </td>
> >             </tr>
> >             <tr>
> >               <td width="40%" class="bodyTxt">
> >                 <b>State</b>
> >               </td>
> >               <td width="60%" class="bodyTxt">
> >                 <asp:textbox id="State" width="25" textmode="SingleLine"
> > cssclass="textBoxes" runat="server"/>
> >               </td>
> >             </tr>
> >             <tr>
> >               <td width="40%" class="bodyTxt">
> >                 <b>Your Interest</b>
> >               </td>
> >               <td width="60%" class="bodyTxt">
> >                 <asp:textbox id="Interest" textmode="MultiLine" rows="4"
> > columns="25" cssclass="textBoxes" runat="server"/>
> >               </td>
> >             </tr>
> >             <tr>
> >               <td colspan="2"><hr width="75%" noshade ></td>
> >             </tr>
> >             <tr>
> >               <td width="40%" class="bodyTxt">
> >                 <b>Username*</b>
> >               </td>
> >               <td width="60%" class="bodyTxt">
> >                 <input type="text" name="Username" id="Username"
> > class="textBoxes" />
> >               </td>
> >             </tr>
> >             <tr>
> >               <td width="40%" class="bodyTxt">
> >                 <b>Password*</b>
> >               </td>
> >               <td width="60%" class="bodyTxt">
> >                 <input type="text" name="Password" id="Password"
> > class="textBoxes" />
> >               </td>
> >             </tr>
> >             <tr>
> >               <td colspan="2" align="right" class="bodyTxt">
> >                 <b><asp:linkbutton id="joinSubmit" onclick="LogNewUsr"
> > text="Join Now" runat="server"/></b>
> >               </td>
> >             </tr>
> >           </table>
> >         </form>

 
 
 

1. Javascript Form validation

Help!

I am developing a Corporate Directory webapp (well migrating from asp
actually but writing from scratch).

I have a custom control that allows the user to send SMS messages. As you
probably well know there is a limit to the number of characters you can
send.

In my old asp/javascript app when the user entered characters into the
message box a javascript function was called do decrement a value in another
(readonly) textbox.

However, I have ported this to .NET (c#) and it is kind enough to put a SMS:
(sms is the name of the control) infront of each control name, therefore the
javascript function cannot access these elements (syntax errors - "expected
;").

Does anyone know of a workaround for my problem (without posting back for
every keypress!)

Any help is greatly appreciated,

Ross Harper
Web Developer
Fujitsu-Siemens Computers

email: ross dot harper at fujitsu-siemens dot com

spaces)

2. Anyone for Java?

3. Javascript Form Validation

4. upgrade from win98 crashes 1/2 way thru with: drive c corrupt - cannot fix

5. Javascript validation Vs asp.net Validation controls.

6. Port I/O & testcfg.sys

7. validation with validation control and javascript

8. PMMail on ftp.cdrom.com??

9. Javascript Form Validation

10. Javascript Form validation

11. form validation using javascript

12. About Client Side validation and submitting the form using Javascript

13. JavaScript Form Validation in Asp.Net