Pass a hidden field value based on which button is clicked with JavaScript

前端 未结 4 1732
忘掉有多难
忘掉有多难 2021-02-20 01:43

I have a form with two buttons, each with onclick = this.form.submit(). I have a hidden field in the form, and I would like the value of the field to be different based on which

4条回答
  •  隐瞒了意图╮
    2021-02-20 02:19

    You could pass the value to which you want to set the hidden input to a function you create:

    function handleClick(val){
        document.getElementById('HiddenInputID').value = val;
        return true;
    }
    

    and then code the buttons using the onclick to pass whichever value you'd like:

    
    
    

提交回复
热议问题