Jump to content


Photo

form processing


  • Please log in to reply
4 replies to this topic

#1 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 26 September 2006 - 08:30 PM

I'm using a javascript file with my site that requires that i do not name my submit inputs, but i need to get the submit value so that my script executes the correct pieces of code depending on which submit input has been pressed, because some of my pages have several forms on them.

Is there any way to find which submit has been pressed, or which form it was in or something like that without me having to name my submit inputs and get there values with $_POST['submitnamegoeshere']; ?

Thanks in advnace for any help, and please say if you need more details.

#2 tleisher

tleisher
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 26 September 2006 - 08:35 PM

Check other data, instead of the submit, check another peice of input that is submit.

#3 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 26 September 2006 - 08:39 PM

If i do that, then people could fill in a form and press the submit button from a different form and it would still process their input.

#4 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 26 September 2006 - 09:04 PM

What if i name the form rather than the submit input? Is there anyway to get a value for the form that has been submitted?

#5 KevinM1

KevinM1
  • Moderators
  • Snarkimus Prime
  • 5,248 posts

Posted 26 September 2006 - 09:44 PM

JavaScript automatically keeps track of forms and their elements using DOM Level 0 syntax:

document.forms[i].elements[i].value

Elements are inputs, selects, and textareas.  So, if the form you're talking about is the first form on your page, and you want to get to the fourth form element, calling
document.forms[0].elements[3]
will work.

Unfortunately, using this method isn't very efficient if you're doing a lot with forms as JavaScript will walk the DOM every time you explicitly use that syntax.  If you're going to be using the same element a lot, store it in a variable (something like
var elem = document.forms[0].elements[1]
for the second element of the first form, for example).  That will cut down on the overhead incurred by the Level 0 syntax as the script won't traverse the hierarchy every time it's called.
Using 'global' is a sign of doing it wrong




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users