473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Dummy needs a simple problem solved.

I found this piece of JS which serves exactly what I need. It validates if
the input is exactly five numberic characters.

When it is validated, the form action is not carried out. What should I add
to the code so that the form action is carried out?

P/s: I do not know JS at all.

==================================
<html>
<head>
</head>
<body>

<script language="JavaScript1.2">
function checkpostal(){
var re5digit=/^\d{5}$/ //regular expression defining a 5 digit number
if (document.myform.RecordID.value.search(re5digit)==-1) //if match failed
alert("Please enter a valid 5 digit number.")
}
</script>

<form name="myform" ACTION="cgi-bin/dbase/dbase.cgi" METHOD="POST">
<input type="text" name="RecordID" size=15>
<input type="button" onClick="checkpostal()" value="check">
</form>
</body>
</html>
Jul 20 '05 #1
2 1617
"Blue®" <su*******@myjaring.net> writes:
I found this piece of JS which serves exactly what I need. It validates if
the input is exactly five numberic characters.

When it is validated, the form action is not carried out. What should I add
to the code so that the form action is carried out? P/s: I do not know JS at all.
Or HTML?
Change <input type="button" ...> to <input type="submit" ...>

However, then it will always submit. The "checkpostal" function
doesn't return any value, so there is no way for the rest of the
page to know whether the validation succeeded.

Try this:

Remeber to add a <!DOCTYPE> declaration. It is required for HTML 4. <html>
<head>
</head>
<body>

<script language="JavaScript1.2">
In HTML 4 and later, the "type" attribute is required. The "language"
attribute is deprecated, and should be omitted. If it is included,
don't use the version number 1.2 unless you know what the difference
between 1.2 and 1.3 is, and in which browsers it makes a difference
(i.e., just don't).
<script type="text/javascript">

function checkpostal(){
var re5digit=/^\d{5}$/; //regular expression defining a 5 digit number
if (document.myform.RecordID.value.search(re5digit)==-1) {//if match failed
alert("Please enter a valid 5 digit number.");
return false;
}
return true;
} </script>

<form name="myform" ACTION="cgi-bin/dbase/dbase.cgi" METHOD="POST">
It is smarter to add validation to the submit event of the form, then
it is checked no matter how the form is submitted.

<form .... onsubmite="return checkpostal()">
<input type="text" name="RecordID" size=15>
<input type="button" onClick="checkpostal()" value="check">
Just make it a submit button then:
<input type="submit" value="check">
</form>
</body>
</html>


Good luck.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
Thanks, Lasse. It works!!!

I spent the whole morning for it. Luckily you stepped in. The final code is
as below:

==================================
Lawrence Lam
Keywords: Validate JS Javascripts input form digit digits number character
characters
==================================

<script type="text/javascript">

function checkpostal(){
var re6digit=/^\d{6}$/; //regular expression defining a 6 digit number
if (document.myform.RecordID.value.search(re6digit)==-1) {//if match
failed
alert("Please enter a valid 6-digit number.");
return false;
}
return true;
}
</script>
<FORM name=myform ACTION="cgi-bin/dbase/dbase.cgi" METHOD="POST"
onsubmit="return checkpostal()">
<b>Quick Machine Search<br>
</b>Please enter <i>Record ID</i>:<br>
<input type=text name="RecordID" size="16"><font color="#808080"> <br>
</font>
<input type=submit value="Search Machine"><hr color="#FF0000"
size="1"></form>
Jul 20 '05 #3

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

Similar topics

4
by: John | last post by:
I am new to using Python. Everytime I run this program it prints "The lowest common factor is 0", no matter what numbers I use. Can anybody see anything wrong with my program? Thanks in advance. ...
0
by: Jonathan Fine | last post by:
I'd appreciate comments on what I'm doing. Please be kind, I'm a new kid on the block. Here's my application. I'm writing some test code. (I'm a recent convert to unit testing.)
3
by: lonelyplanet999 | last post by:
Hi, I'm a newbie to perl and is now studying about perl programming, I read some perl programming tutorials online (enter 'Perl tutorial' at google.com) and also find some sample perl scripts...
4
by: wireless | last post by:
I've written code that dynamically builds an sql query based on various constraint possibilities. The problem is the code would have been very complex had I not come up with a dummy constraint...
1
by: CSDunn | last post by:
Hello, I am working with a vb6 Windows application that runs on Tablet PC's. There are about five SQL Server 2000 databases that tie into the application. SQL Server MSDE runs on the tablets,...
15
by: glenn | last post by:
Hi folks, I have a DropDownList in a DataGrid that is populated from records in a database. I want to add a value that might be a string such as "Select a Company" for the first item since an...
13
by: jtric | last post by:
Very new to XML/XSL, so please forgive me if this is an incredibly simple question. I've been pulling my hair out over this for several days now. I'm working on an internal application that takes...
3
by: Simon Brooke | last post by:
As various people will have noticed, I've been having a lot of trouble with XSL lately. Brief history: I wrote myself an XML toolkit back in 2000, and it worked well enough for me, so it's been...
35
by: erik gartz | last post by:
Hi. I'd like to be able to write a loop such as: for i in range(10): pass but without the i variable. The reason for this is I'm using pylint and it complains about the unused variable i. I can...
21
by: Prisoner at War | last post by:
Hi, People, Is it possible to have an "empty" or "dummy" <a href***without*** the browser jumping back up the page?? I have a hyperlink that doesn't point to another document, but is used to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.