Prevent form submission on Enter key press

前端 未结 19 1962
失恋的感觉
失恋的感觉 2020-11-22 04:18

I have a form with two text boxes, one select drop down and one radio button. When the enter key is pressed, I want

19条回答
  •  灰色年华
    2020-11-22 04:53

    Use event.preventDefault() inside user defined function

    ...

    function userFunction(ev) 
    {
        if(!event.target.send.checked) 
        {
            console.log('form NOT submit on "Enter" key')
    
            ev.preventDefault();
        }
    }
    Open chrome console> network tab to see
    
      
    submit on enter

提交回复
热议问题