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!

Simple validation question 1

Status
Not open for further replies.

pgferro

Programmer
Aug 21, 2001
111
BS
Hi guys,

I know this sound trivial, but I cannot find a way to do this simple task.

I have a form which is repeated in various pages with different values, and only one text field. In the same page (php) the same form is double, with a different name in case it is an update or a add action in the database.

I have this simple js that I use on an onclick of an image :
Code:
<A class="aform" href="javascript: submitform()">
----
function submitform()
{
  document.forms[0].submit();
}
----

Is there a way to validate the single field (whose name changes in several pages) without defining it manually in every page ?

In other word, would it be possible to use something like :

submitform(fieldName)

Thanks !

--
PG
 
Sure!
Code:
function submitForm(fldName)
{
  var f = document.forms[0];
  var t = f.elements[fldName]; // <-- this is the important bit
  if (t is valid) // add your validation checks here
    f.submit();
  else
    alert("t is not valid!");
}

--Chessbot

"In that blessed region of Four Dimensions, shall we linger on the threshold of the Fifth, and not enter therein? Ah, no! [...] Then, yielding to our intellectual onset, the gates of the Sixth Dimension shall fly open; after that a Seventh, and then an Eighth -- --" Flatland, A. Square (E. A. Abbott)
 
No problem.

--Chessbot

"In that blessed region of Four Dimensions, shall we linger on the threshold of the Fifth, and not enter therein? Ah, no! [...] Then, yielding to our intellectual onset, the gates of the Sixth Dimension shall fly open; after that a Seventh, and then an Eighth -- --" Flatland, A. Square (E. A. Abbott)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top