Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
163
rated 0 times [  164] [ 1]  / answers: 1 / hits: 25721  / 15 Years ago, tue, november 10, 2009, 12:00:00

Ok, this is less of a question than it is just for my information (because I can think of about 4 different work arounds that will make it work. But I have a form (nothing too special) but the submit button has a specific value associated with it.



<input type='submit' name='submitDocUpdate' value='Save'/>


And when the form gets submitted I check for that name.



if(isset($_POST['submitDocUpdate'])){ //do stuff


However, there is one time when I'm trying to submit the form via Javascript, rather than the submit button.



document.getElementById(myForm).submit();


Which is working fine, except 1 problem. When I look at the $_POST values that are submitted via the javascript method, it is not including the submitDocUpdate. I get all the other values of the form, but not the submit button value.



Like I said, I can think of a few ways to work around it (using a hidden variable, check isset on another form variable, etc) but I'm just wondering if this is the correct behavior of submit() because it seems less-intuitive to me. Thanks in advance.


More From » form-submit

 Answers
12

Yes, that is the correct behavior of HTMLFormElement.submit()



The reason your submit button value isn't sent is because HTML forms are designed so that they send the value of the submit button that was clicked (or otherwise activated). This allows for multiple submit buttons per form, such as a scenario where you'd want both Preview and a Save action.



Since you are programmatically submitting the form, there is no explicit user action on an individual submit button so nothing is sent.


[#98340] Friday, November 6, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
reecep

Total Points: 141
Total Questions: 95
Total Answers: 113

Location: Finland
Member since Mon, Nov 8, 2021
3 Years ago
reecep questions
Wed, Dec 8, 21, 00:00, 3 Years ago
Fri, Jul 30, 21, 00:00, 3 Years ago
Wed, Nov 18, 20, 00:00, 4 Years ago
Sat, Mar 14, 20, 00:00, 4 Years ago
Mon, Feb 3, 20, 00:00, 4 Years ago
;