2015-03-03 38 views
2

我已經使用jQuery的1.11.2.min.js和Chrome 40.0.2214.115重定向使用jQuery

在用戶註冊表單,如果現場的人是空的servlet類文件我想顯示該警報消息。否則用戶將重定向到servlet類文件,在那個servlet類中,我編寫了db連接以插入用戶詳細信息。

我的用戶註冊的html代碼是

<script type="text/javascript" src="js/plugins/jquery-1.11.2.min.js"></script> 
<script> 
$(document).ready(function() 
     { 
    $("#submitid").click(function() 
     { 
     var fname=$("#firstname2").val(); 
     var lanme=$("#lastname2").val(); 
     var email=$("#email2").val(); 
     var mobileno=$("#mobileno").val(); 
     var username=$("#username").val(); 
     var pass=$("#password").val(); 
     if(fname==''||lname==''||email=''||mobileno==''||username==''||pass=='') 
      { 
      alert("Enter all fields"); 
      $("#userform").focus(); 

      } 
     else 
      window.location.href("Userdetailsins.java"); 
      }); 
     });</script> 
</head> 

<body> 

<form class="stdform stdform2" method="post" id="userform"> 
<label>First Name</label> 
<input type="text" name="userfname" id="firstname2" class="longinput" /> 
<label>Last Name</label> 
<input type="text" name="userlname" id="lastname2" class="longinput" /> 
<label>Email</label> 
<input type="text" name="mailid" id="email2" class="longinput" 
<label>Mobile no</label> 
<input type="text" name="mobno" id="mobileno" class="longinput" 
<label>User name </label> 
<input type="text" name="username" id="username" class="longinput" /> 
<label>User Password </label> 
<input type="password" name="password" id="password" class="longinput" /></span>      
<input type="reset" value="Reset Button" /> 
<input type="submit" id="submitid" name="submitid" value="Next"/> 
    </form> 
</body> 
</html> 

它不顯示提示信息時,字段爲空,並且不重定向到另一種形式。即使我嘗試與另一個HTML文件重定向它不起作用。重定向我按照下面

//$(location).attr('href',"http://www.google.com"); 
     //window.open("next.html"); 
     //$("#submitform").focus(); 

     //$(window.location).attr('href', 'http://www.google.com'); 

     //window.navigator("next.html"); 
     //self.location="next.html"; 

    //top.location="next.html"; 
    //var url="www.google.com" 
     //window.location.replace(url); 

    //window.location.href("next.html"); 
    window.open("next.html"); 

的window.open()方法的作品所示的準則,但我不希望打開一個單獨的窗口,我只是重定向。請任何人幫助解決這個問題。

感謝....

+0

通過使用這款U得到任何錯誤window.location.href( 「next.html」); @Asha – 2015-03-03 09:50:46

+0

謝謝@編碼解密我沒有任何錯誤。該表單駐留在同一頁面上沒有重定向到next.html。 – Asha 2015-03-03 09:58:02

+0

點擊你需要重定向到另一個頁面的權利? – 2015-03-03 10:08:58

回答

2

使用此

function nextredirect(){ 
    window.location.href = 'next.html'; 
} 

jQuery的

$('#submitid').click(function(){ 

if($('#firstname2').val() == ""){ 
alert('Please enter the first name'); 
}else{ 
window.location.href = 'next.html'; 
} 
}); 

的Html

<input type="button" id="submitid" name="submitid" value="Next" onclick="nextredirect()"/> 
+0

感謝它在onclick事件。但我想驗證使用jQuery的形式,然後只有我會重定向到下一頁...有什麼辦法在jQuery中? @Coding cracker – Asha 2015-03-03 10:57:15

+0

是的阿莎當然爲什麼不等待更新我的代碼:) @Asha – 2015-03-03 10:58:03

+0

檢查我更新的答案@Asha – 2015-03-03 11:00:28