0
<%-- 
    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>
4
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by ~s.o.s~
0

I want to add a javascript in the jsp form for the form validation of numbers in the pincode text area.I know it's easy but just not clicking :(.Any help would be appreciated.

0

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.

0

This javascript is giving an error

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.

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

1

> 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:

// This restricts the pin code to only digits with at least one
// digit required.
/^[0-9]+$/.test(txtField.value)

Edited by ~s.o.s~: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.