2015-09-28 61 views
4
$(document).ready(function() { 
    $("#submit").click(function() { 
    var value = document.getElementById("txt_sketch_no").value; 
    var process_id = document.getElementById("process_id").value; 
    var length = value.length; 
    if (length <= 0) { 
     alert("Please Enter the sketch card"); 
     window.location = 'sketch_screen.php'; 
    } else { 
     window.location = 'dws_Support.php'; 
    } 
    }); 
}); 
<form action="" method="post" autocomplete="off"> 
    <div class="container"> 
    <div class="alert alert-success" id="alert_box"> 
     <input type="hidden" name="process_id" id="process_id" value="<?php echo $process_id; ?>"> 
     <label>Enter the Sketch Card No :</label> 
     <input type=text id="txt_sketch_no" name="txt_sketch_no"> 
     <input type=submit id="submit"> 

在上面的代碼,我想在頁面的JavaScript幫助重定向,但在其他部分window.location = 'dws_Support.php'不工作,但是,當我們在其他部分與提醒它就會顯示但沒有重定向到'dws_Support.php'。請幫忙。window.location =''不起作用;

+2

使用window.location.href或window.location.assign –

+0

我的猜測是你提交表單之前驗證與jQuery的。先嚐試驗證它。 http://stackoverflow.com/a/15072147/797495 –

+0

你確定'if'部分中的重定向工作嗎? –

回答

0

,你不需要爲使用JavaScript,問題來自於你的屬性操作表單重定向形式,所以使用此代碼:

<script src="js/jquery.js"></script> 
<script> 
    $(document).ready(function() { 
     $("#submit").click(function() { 
      var value = document.getElementById("txt_sketch_no").value; 
      var process_id = document.getElementById("process_id").value; 
      var length = value.length; 
      if (length <= 0) { 
       alert("Please Enter the sketch card"); 
       window.location = 'sketch_screen.php'; 
      } else { 
       window.location = 'dws_Support.php'; 
      } 
     }); 
    }); 
</script> 
</head> 
<body style="background-color: #73C5E1" > 
     <div class="container"> 
      <div class="alert alert-success" id="alert_box"> 
       <input type="hidden" name="process_id" id="process_id" value="12"> 
       <label> Enter the Sketch Card No : </label> 
       <input type="text" id="txt_sketch_no" name="txt_sketch_no"> 
       <input type = "submit" id="submit"> 
      </div> 
     </div> 
</body> 

希望它能幫助你。

4

嘗試使用 window.location.href='dws_Support.php'

+3

也許他在上面的評論中看到了答案。大聲笑。 – aldrin27

0

這是你的失敗:你正在聽click,但是submit事件的形式剎車你的邏輯。這是固定的:

$(document).ready(function() { 
    $("form").on('submit', function(e) { 
    e.preventDefault(); 

    var value = document.getElementById("txt_sketch_no").value; 
    var process_id = document.getElementById("process_id").value; 
    var length = value.length; 
    if (length <= 0) { 
     alert("Please Enter the sketch card"); 
     window.location = 'sketch_screen.php'; 
    } else { 
     window.location = 'dws_Support.php'; 
    } 
    }); 
}); 
0

很高興如果你找到答案,但你的編碼沒有問題,你只是錯過了返回false;重定向後..

<script src="jquery-1.4.js"></script> 
<script type="text/javascript"> 
<!-- 
    $(document).ready(function() { 
     $("#submit").click(function() { 
     var value = document.getElementById("txt_sketch_no").value; 
     var process_id = document.getElementById("process_id").value; 
     var length = value.length; 
     if (length <= 0) { 
      alert("Please Enter the sketch card"); 
      window.location = '/sketch_screen.php'; 
      return false; 
     } else { 
      window.location = 'dws_Support.php'; 
      return false; 
     } 
    }); 
}); 
//--> 
</script> 

希望這可以解決您的問題。 :)