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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate Form Data Against Database

Status
Not open for further replies.

Lambro

Programmer
Aug 22, 2001
258
US
I have a textbox on my form that a user enters a part number. When the user tabs off the textbox I would like a message box to popup if the item does not exist in the database.
 
Two ways to do this (possibly more):

(1) Build the page with ALL relevant part numbers saved to a JavaScript array and run a comparison with the onblur event from the textfield.

(2) Have a hidden iframe on the page and launch a check on the database there with the textfield's onblur event (my usual approach).

For example, the iframe might be:

Code:
<iframe id='checkPart' width='0' src='partForm.html'></iframe>

partForm.html might be:
Code:
<html>
<body>
<form name='checkPartForm' action='checkPartDatabase.jsp'>
<input type='hidden' name='partNumber'>
</form>
</body>
</html>

checkPartDatabase.jsp is whatever you have to do to run a check. If you want to pop-up a message at the end of it, then something like this could go there:

Code:
... <JSP code>
<html>
<head>
<script>
alert("Part number <%=partNumber%> is a <%=description%>");
this.location = partForm.html; //readies it for the next go
</script>
</head>
</html>

And if your parent page's textfield's onblur event calls a function (say 'checkPart()'), you will need this in the JavaScript of the parent page:

Code:
function checkPart()
{
 checkPartFrame.checkPartForm.partNumber.value = document.formName.textFieldName.value;
 checkPartFrame.checkPartForm.submit();
}

'hope that helps.

--Dave
 
One 'oops' in the above:

if you use the JavaScript in the checkPart() function I provided above, you will have to use 'checkPartFrame' as the ID of the IFRAME (as opposed to just 'checkPart' which is what I used in the sample provided).

--D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top