Javascript submit does not contain submit button value
P粉957661544
P粉957661544 2023-10-22 09:40:15

Well this is not a question but just for my information (since I can think of about 4 different workarounds to make it work. However I have a form (nothing special) but the submit button has something to do with The specific value associated with it.

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

After submitting the form, I check the name.

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

However, one time I tried to submit the form via Javascript instead of the submit button.

document.getElementById("myForm").submit();

Everything is working fine except 1 problem. When I look at the $_POST value submitted via the javascript method, it does not include SubmitDocUpdate. I get all other values ​​of the form but not the submit button value.

Like I said, I can think of a few ways to fix it (using a hidden variable, checking isset on another form variable, etc.), but I just want to know if this is the correct behavior for Submit(), Because it doesn't seem very intuitive to me. Thanks in advance.

P粉957661544
P粉957661544

reply all(2)
P粉131455722

Use jQuery 1.0 or higher:

$('input[type="submit"]').click();

I was actually solving the same problem when I stumbled across this post. click() without any parameters triggers a click event on any element you select: http://api.jquery.com/click/

Popular topics
More>
Latest downloads
More>
web effects
Website source code
Website materials
Front end template
About us Disclaimer Sitemap
PHP Chinese website:Public welfare online PHP training,Help PHP learners grow quickly!