Jquery - operators in if statement

I'm trying to submit a form to a different location depending on which (of two) form fields have been filed in. It work when both fields have a value but when only one if field has a value it always submits to the suppliers/category/ URL. Here is my code. $('#suppliersForm').submit(function() { catVal = $('#category').val() keywordVal = $('#keywords').val() if( $('#category').val() && $('#keywords').val() ) { var searchString = 'http://#cgi.server_name#/suppliers/searchresults/' + catVal + '/' + keywordVal window.location.replace(searchString); } else if( $('#category').val() || $('#keywords').val() ) { var searchString = 'http://#cgi.server_name#/suppliers/category/' + catVal window.location.replace(searchString); } else if( $('#keywords').val() || $('#category').val() ) { var searchString = 'http://#cgi.server_name#/suppliers/keywords/' + keywordVal window.location.replace(searchString); } return false; }); Any help would be appreciated

以上就是Jquery - operators in if statement的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏