Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Input validation

Status
Not open for further replies.

ianfo

Programmer
Aug 20, 2002
29
GB

Hi,

I've got a really simple html form that takes user input into one box (input name=patchid)

Can someone give me an example of how I would validate patchid to make sure it is a 6 digit number?

I don't know any javascript but i've tried a couple of things with no success so far so any help would be much appreciated.

Thanks
 
This seem to be one of the most simple ways:
[tt]
function checkId(field)
{
id = parseInt(field.value);
if ( !isNaN(id) && id>99999 )
return true
else
return false
}
[/tt]
Use it like this:

<form name=&quot;f1&quot; action=&quot;&quot; onsubmit=&quot;return checkId(document.f1.patchid)&quot;>
<input type=&quot;text&quot; input name=&quot;patchid&quot;>
<input type=&quot;submit&quot;>
 
I'm having some problems getting it to work

All i've changed on the line below is action=&quot;cgi-bin/getpatch&quot;

<form name=&quot;f1&quot; action=&quot;&quot; onsubmit=&quot;return checkId(document.f1.patchid)&quot;>

Do I need to change document to anything or should it work as it is?

thanks
 
No any changes needed. Of course you should specify the target of server-side form processing in &quot;action&quot;.
Didn't you forget to place the script in the <head> of your page?
&quot;having some problems getting it to work&quot; - this doesn't tell anything.
 
I've put the script in between <head> and </head>

I'm getting a syntax error pop up window when I try to load the page. I'll check it over again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top