javascript - Fail to call last if condition

888

Currently I'm working with jQuery. My question is, why when I filled all the text box and click submit button, why is it not going to'/timesheets_app/index.php/searchall'? Here is my snippet:

$(document).ready(function() {
    $("#search-form").submit(function() {
        if ($("#fieldDari").val() == '' && $("#fieldKe").val() == '' && $("#fieldNama").val() == '')
        {
            $("#search-form").attr("action", "/timesheets_app/index.php/karyawan2");
        } else if ($("#fieldDari").val() == '' && $("#fieldKe").val() == '')
        {
            $("#search-form").attr("action", "/timesheets_app/index.php/searchname");
        } else if ($("#fieldNama").val() == '')
        {
            $("#search-form").attr("action", "/timesheets_app/index.php/searchdate");
        } else if ($("#fieldNama").val() != '' && $("#fieldDari").val() != '' && $("#fieldKe").val() != ''){
            $("#search-from").attr("action", "/timesheets_app/index.php/searchall");
        }
    });
});
629

Answer

Solution:

You don't have a .val() on the last one.

$("#fieldKe").val() != ''

You also have a typo on the$("#search-form").attr(...)

900

Answer

Solution:

In

else if ($("#fieldNama").val() != '' && $("#fieldDari").val() != '' && $("#fieldKe") != '')

$("#fieldKe") != ''

should be changed to

$("#fieldKe").val() != ''

People are also looking for solutions to the problem: PHP skips 6 rows when calling from MySQL

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.