简体   繁体   中英

How to return post form value and action after perform onclick function in php?

In this code I am simply do if($("#teacherID").val()=='0') then it show alert which is working fine but after change value of $("#teacherID").val() then it not return to form action. So, How can I do this? Please help me.

<script>
    $(".paypay").click(function(e){
        e.preventDefault();
        if($("#teacherID").val()=='0')
        {
            alert("Please select academic partner!");
        }
    });
</script>   
<form action="<?php echo base_url() ?>mymain/xyz" onsubmit="return confirm('Do you really want to submit the form?');" method = "post">               
    <label class="nexCheckbox">Check
        <input type="checkbox" name="select_all" id="select_all">
        <span class="checkmark checkmark-action-layout"></span>
    </label>

    <input type="submit" class="btn btn-primary etsfilertButton disabled paypay" name="Pay" value="Pay" disabled>
</form> 

Thank You

Because you use e.preventDefault() , it will not submit the form on its own - you prevent that behavior. You can find the form and submit it after the checks are done.

<script>
    $(".paypay").click(function(e){
        e.preventDefault();

        if ($("#teacherID").val() == '0') {
            alert("Please select academic partner!");
            return;
        }

        $(this).closest("form").submit();
    });
</script> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM