How to prevent form element from sending some fields we don't want?

后端 未结 3 1763
自闭症患者
自闭症患者 2020-11-30 10:35

I have a form element that contains about 5 fields which final query is going to create by processing values those fields. So I want to send only final query, not all of tho

3条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 11:17

    Remove the element on submit.

    On the onsubmit handler:

    $(formElement).submit(function() {
        $(this.field1).remove(); //removing field 1 from query
        return true; //send
    });
    

    Disabling the form element also stops it from being entered into the query.(tested on Chrome)

    $(formElement).submit(function() {
        this.field1.disabled = true;
        return true; //send
    });
    

提交回复
热议问题