Jump to content

form processing


Tandem

Recommended Posts

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.
Link to comment
https://forums.phpfreaks.com/topic/22156-form-processing/
Share on other sites

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

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

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 [code]document.forms[0].elements[3][/code] 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 [code]var elem = document.forms[0].elements[1][/code] 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.
Link to comment
https://forums.phpfreaks.com/topic/22156-form-processing/#findComment-99245
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.