Tandem Posted September 26, 2006 Share Posted September 26, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/22156-form-processing/ Share on other sites More sharing options...
tleisher Posted September 26, 2006 Share Posted September 26, 2006 Check other data, instead of the submit, check another peice of input that is submit. Quote Link to comment https://forums.phpfreaks.com/topic/22156-form-processing/#findComment-99197 Share on other sites More sharing options...
Tandem Posted September 26, 2006 Author Share Posted September 26, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/22156-form-processing/#findComment-99200 Share on other sites More sharing options...
Tandem Posted September 26, 2006 Author Share Posted September 26, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/22156-form-processing/#findComment-99214 Share on other sites More sharing options...
KevinM1 Posted September 26, 2006 Share Posted September 26, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/22156-form-processing/#findComment-99245 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.