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

How do I validate form input against a delimited list 1

Status
Not open for further replies.

LyndonOHRC

Programmer
Sep 8, 2005
603
US
I have a text form input that I want to validate but can't get it to work. I'm getting -1 returned from the indexOf function even when the value is in the list. I'm guessing -1 is what that function returns on a no find.

My input name is dynamic so I am passing its value using the "this" variable.

Thanks

Form code:
Code:
<input class="SmallForm" 
	name="txtLic_Type#Trim(ToString(lic.CurrentRow))#" 
	value="#lic.lic_type#" 
	size="3" 
	maxlength="3" 
        onblur="IsInList(this,'001,007,425,DP,XR,N/A')">

Javascript function:
Code:
function IsInList(FormValue,ValidList){
var FormValueTrimmed=FormValue.replace(/^\s+|\s+$/g, ""); //trim leading and trailing spaces
var i=ValidList.indexOf(FormValueTrimmed);
alert(i);
}

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Without looking too much in depth at what you have, you are pulling 'this' into IsInList. 'this' is an object. You can pull 'this', but in the function IsInList, you need to grab this.value before you can do anything with it.

Or, you can send this.value as a parameter of IsInList


Code:
<input class="SmallForm" 
    name="txtLic_Type#Trim(ToString(lic.CurrentRow))#" 
    value="#lic.lic_type#" 
    size="3" 
    maxlength="3" 
        onblur="IsInList(this[!].value[/!],'001,007,425,DP,XR,N/A')">

OR


Code:
function IsInList([!]FormObj[/!],ValidList){
[!]var FormValue = FormObj.value[/!];
var FormValueTrimmed=FormValue.replace(/^\s+|\s+$/g, ""); //trim leading and trailing spaces
var i=ValidList.indexOf(FormValueTrimmed);
alert(i);
}


[monkey][snake] <.
 
Outstanding.

Thanks so much!

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top