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

PLease help With field Validation I am new To JAvaScript...

Status
Not open for further replies.

natedogg

Programmer
Apr 12, 2003
3
NZ
Hello,
I have an HTML form that Sends Search Criteria to a DB and Gets back the results,

I have been Trying to Validate these fields, in a way that when the user enters the search criteria, for example AbCd, the
Script will Pass alphabetic characters, anything matching abcd regardless of the CASE. does anyone have any Ideas? if so please help!
I am not really Sure What the code should look like,
in this case, I am pretty new to JavaScript....


function convertStr(str) {
if (document.form.model.value =" ") \\not sure what the value should be equal to?
Then
\\Change criteria to both upper and lowecase and send both uppercase and lowercase search criteria
str = str.replace ???????

 
JavaScript
Code:
function checkForm(form_ref) {
  if (form_ref.model.value == "")
    window.alert("Please provide a search value")
    return false
  }

  var sV = form_ref.model.value
  sV = sV.toUpperCase() + ' OR ' + sV.toLowerCase()
  form_ref.model.value = sV
  return true
}
Then in your form.
Code:
<form ...... onSubmit=&quot;return checkForm(this);&quot;>
This is a very rudimentary example as I don't know the inner workings of your search method. However, using this script, if someone submitted AbCd, the script would actually pass 'ABCD OR abcd' to your form handler.

ToddWW
 
ToddWW - your method works but with the exception you noted. Without knowing the search method it's impossible to solve this problem. IF the database being searched stores the string as upper or lower case, your method works BUT if it has been (poorly) setup to allow it to be stored as AbCd then your search strings won't automatically work.
NAteDogg - any idea on HOW the data is being stored?
George K
 
Well, let's start from the beginning. You stated that you have a form that sends search criteria to a DB. Who's DB, your's or are you setting up a form to post to an actual internet search engine ??

ToddWW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top