Change value of input and submit form in JavaScript

前端 未结 8 1446
死守一世寂寞
死守一世寂寞 2020-11-30 03:20

I\'m currently working on a basic form. When you hit the submit button, it should first change the value of a field, and then submit the form as usual. It all looks a bit li

8条回答
  •  隐瞒了意图╮
    2020-11-30 03:23

    You could do something like this instead:

    And then modify your DoSubmit function to just return true, indicating that "it's OK, now you can submit the form" to the browser:

    function DoSubmit(){
      document.myform.myinput.value = '1';
      return true;
    }
    

    I'd also be wary of using onclick events on a submit button; the order of events isn't immediately obvious, and your callback won't get called if the user submits by, for example, hitting return in a textbox.

提交回复
热议问题