473,799 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Client-Side Validation of asp:TextBox with Javascript

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="retur n
validateName(th is);">

and

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

blnEval = reEval.test(the Form.txtName.Va lue)

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!

Nov 17 '05 #1
2 17531
Hi

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

--
Best Regards
Vidar Petursson
=============== ===============
Microsoft Internet Client & Controls MVP
=============== ===============
"Matthew Wieder" <De*********@Sa toriGroupInc.co m> wrote in message
news:3F******** ******@SatoriGr oupInc.com...
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="retur n
validateName(th is);">

and

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

blnEval = reEval.test(the Form.txtName.Va lue)

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!

Nov 17 '05 #2
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


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
18705
by: Jack | last post by:
Hello, I wrote this code: <%@ LANGUAGE=VBScript %> <SCRIPT LANGUAGE=JavaScript> function CustomerNameChange() { var forwarding_dbX; var CustomerTableX; set forwarding_dbX = Server.CreateObject("ADODB.Connection"); forwarding_dbX.Open "Forwarding";
1
1985
by: Mr. x | last post by:
.... The second time I am sending this email ... .... I want a good solution, please. .... Thanks :) What I need is moving xml data from client to server & vice versa, but not using xml file. I did something like this : In server (VBScript) : -----------------------------
1
2013
by: Alfredo Magallón Arbizu | last post by:
Hello, I need to pass the contents of a dataset to the client in order to use these contents with javascript. What is the best way to achieve that? Normally I use controls like a grid or text boxes and then I read the values using javascript objects.
1
3622
by: John | last post by:
I have a panel on a webpage. I use client Javacript to manipulate its visibility using something like: Panel.style.display = 'none'. During a postback, getting the Visible attribute always returns true whether the panel was visible or not. Is there another Javascript method to turn on/off a Panel's visibility *and* whose attribute can be read from code behind? I am thinking of using a hidden field as a flag placeholder which can be used...
0
990
by: pmclinn | last post by:
In the .net designer wrote a proceedure named 'Fireitup'. How do I call on this proceedure from client javascript.
2
1135
by: Steve Murphy | last post by:
How do you set focus to a particular TextBox in ASP.NET? Thank you in advance.
5
1513
by: Turbo | last post by:
I was trying to find whats so good about ajax. Well i cant say that... but i found a very good link on this site for learning ajax in 30 seconds:- http://sandy007smarty.seo.iitm.ac.in/2006/09/26/ajax-tutorial/
0
922
by: nkw | last post by:
I have two textboxes (tbox1, tbox2) in a step of Wizard control. I use javascript code to clear tbox2 when onblur occurring on tbox1: tbox1.Attributes = "javascript:var tbox2 = document.getElementById('<%=tbox2.ClientID%>'); tbox2.value='';"; 1) I tried to put some non-empty string data in tbox2 and press next button. 2) Then I go back to previous step and leave focus of tbox1 and the screen showed tbox2 is cleared by the javascript...
2
1893
by: www.gerardvignes.com | last post by:
I am using this to load the client JavaScript for a web application when it is selected by the user) via an Ajax connection to the server. I have found only two ways of loading new JavaScript after the web page is loaded. 1. Create a new script element (where head is the id of the head tag): var s = document.createElement('script'); s.setAttribute('type','text/javascript'); s.setAttribute('src', 'scripts/myscript.js');
4
6939
by: Manuel | last post by:
Hello. I need insert a piece of javascript code in a JSTL page, that it will execute always, that is, without events. I use the tag <scriptbut this make that the web don't load correctly. Any idea?
0
10495
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10269
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10248
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7573
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5597
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4148
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.