| | |
Adding form validation for numeric values
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2009
Posts: 10
Reputation:
Solved Threads: 0
JSP Syntax (Toggle Plain Text)
<%-- Document : AddCity Created on : Oct 6, 2009, 9:14:52 PM Author : Vishal --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body onload="ShowMessages();"> <html:form action="AddPage.do"> <p><a href="HomePage.do">HomePage</a></p> Cityname: <input type="text" name="cn" value=""> PinCode: <input type="text" name="pc" value=""><br> <input type="button" name="Submit" value="Submit1" onClick="checkpincode();onSubmit()"> <div id="message" style="position:relative;left:0;top:0;display:none"><html:errors/></div> </html:form> </body> </html> <script> function onSubmit() { document.forms[0].action="AddPageSuccess.do"; document.forms[0].submit(); } function ShowMessages() { var msg= document.getElementById("message").innerHTML; if(msg!=null && msg.length >0) { msg=msg.replace(/<BR>/g,"\n "); msg=msg.replace(/<br>/g,"\n "); alert(msg); document.getElementById("message").innerHTML=""; } } </script>
0
#3 Oct 13th, 2009
onChange - the onchange event occurs when a control loses the input focus and its value has been modified since gaining focus. This attribute applies to the following elements: INPUT, SELECT, and TEXTAREA.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
Join Date: Oct 2009
Posts: 10
Reputation:
Solved Threads: 0
0
#4 Oct 13th, 2009
This javascript is giving an error
The page is giving an error "undefined is null or not an object".Perhaps i need to provide an action path for the checkpincode() javascript.But i don't know where.Or there might be some other reason.
JavaScript Syntax (Toggle Plain Text)
function checkpincode(elem,helperMsg) { var numericExpression=[0-9]; if(elem.value.match(numericExpression)) { return true; } else { alert(helperMsg); elem.focus(); return false; } }
The page is giving an error "undefined is null or not an object".Perhaps i need to provide an action path for the checkpincode() javascript.But i don't know where.Or there might be some other reason.
Last edited by peter_budo; Oct 13th, 2009 at 12:09 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
1
#6 Oct 13th, 2009
> Does [0-9] need to be in quotes?
No, it needs to be placed inside forward slashes to be considered as a regular expression. Of course, if you place them inside quotes, you need to explicitly use the RegExp() constructor.
@vishalanuj
That regex won't work. Try something like:
No, it needs to be placed inside forward slashes to be considered as a regular expression. Of course, if you place them inside quotes, you need to explicitly use the RegExp() constructor.
@vishalanuj
That regex won't work. Try something like:
javascript Syntax (Toggle Plain Text)
// This restricts the pin code to only digits with at least one // digit required. /^[0-9]+$/.test(txtField.value)
Last edited by ~s.o.s~; Oct 13th, 2009 at 12:53 pm.
I don't accept change; I don't deserve to live.
![]() |
Similar Threads
- Javascript form validation to PHP processing (JavaScript / DHTML / AJAX)
- php regex for form validation (PHP)
- PHP Form Validation ??? (PHP)
- sample code for form validation using ajax (JavaScript / DHTML / AJAX)
- coldfusion form validation question (ColdFusion)
- Really Stuck - ASP/Javascript Form Validation (ASP)
- Dreamweaver php form validation and redirect (PHP)
- Help on form validation requested. (PHP)
- Extend Class Characters to numeric Values (Python)
- form validation (PHP)
Other Threads in the JSP Forum
- Previous Thread: JSP and Calendar View
- Next Thread: configuring Tomcat
| Thread Tools | Search this Thread |
apache backbutton combobox connection database development directorystructure dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 network parameters passing ping printinserverinsteadofclient redirect request.getparameter response servlet servletdopost()readxml sessions software ssl state_saving_method stocks sun tomcat tutorial update video web






.Any help would be appreciated.
