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");
}
});
});
Answer
Solution:
You don't have a .val() on the last one.
You also have a typo on the$("#search-form").attr(...)
Answer
Solution:
In
else if ($("#fieldNama").val() != '' && $("#fieldDari").val() != '' && $("#fieldKe") != '')
$("#fieldKe") != ''
should be changed to
$("#fieldKe").val() != ''