Showing error without page refresh

后端 未结 3 567
执念已碎
执念已碎 2021-01-17 04:10

I\'m making a comment feature for my website and need to make it so that after the person submits a comment (and it contains errors), it will show the error without refreshi

3条回答
  •  一个人的身影
    2021-01-17 04:11

    I think it is easier to do the validation at the client side via Javascript. Instead of simply using a button of type submit, write a function and bind it to the button's onclick() event.

    Something like this:

    function submit() {
      if (document.getElementById("myTextarea").value=='') {
        alert("Your comment is too short.");
      }
      else {
        document.getElementById("myForm").submit();
      }
    }
    

提交回复
热议问题