Window.location = '' does not work;

$(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">

In the above code, I would like to redirect the page using Javascript, but window.location = 'dws_Support.php'in another part it doesn’t work, but when we inform that in the else part it is displayed, but not redirected to 'dws_Support.php', Please help.

+4
source share
4 answers

you don't need a form for redirecting using javascript, the problem arises from your attribute action form, so use this code:

<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>

Hope this helps you.

0
source

Try using  window.location.href='dws_Support.php'

+4
source

: 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

, , , return 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>

, .:)

0

Source: https://habr.com/ru/post/1609242/


All Articles