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

validate form text boxes

Status
Not open for further replies.

ibjdt

Programmer
Nov 25, 2002
63
i have a data table containing sometimes hundreds of rows - each with it's own 'edit' link.
the link contains an onclick call to javascript to show a div in the next table row.

Code:
function make(item){ 
		document.getElementById(theDIV).innerHTML = '<form name=invEdit'+item+' onSubmit="return checkInvEdit('+item+');"><input name=VartoChange....>';
}

the div form allows data update, but i can't allow a 0 value so i tried to check the form like this

Code:
function checkInvEdit(item){ 
alert(item);
	var VartoChange = document.invEdit['item'].VartoChange.value;
	if (VartoChange == "" || VartoChange == "0") { alert ('\n- Please enter a non-zero value'); return false; }
}

the alert is a test and it works - passes the correct item number - but not the rest.

Code:
document.invEdit.item is null or not an object

i don't want to loop through all the elements to determine which was submitted because there can be hundreds and it would take too long.

thanks.
 
Your first piece of code, creates a form who's name is composed of the string "invEdit" and a whatever is in the "item" variable.

Assuming its a number say 5 you'd get invEdit5, but that does not make the name an array.

Assuming in your second piece of code "item" is still a number then: invEdit[item] would really be requesting the element 5 in the invEdit array, however there is no invEdit array, because all your forms have a different name.

Instead what you want is to access a form who's name is "invEdit" plus a number so:

document.forms['invEdit'+item].VartoChange.value;











----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top