2016-05-31 180 views
-1

我試圖從一個網頁發送表單數據到另一個使用此: Passing data from one web page to another從一個網頁傳遞表單數據到另一個

我貼我創建的函數的JavaScript代碼:

但問題是,window.location.href不起作用,網頁沒有重定向。

我已經看到控制檯的錯誤,但沒有任何。

誰能告訴問題在哪裏?

編輯1: 驗證功能:

function validate(){ 
      var comment = document.getElementById("comments").value; 
      var gender = document.getElementById("gender").value; 
      var len = comment.length; 
      if (len > 100) 
      { 
       alert("Reduce the length of the comment less than 100 characters"); 
      } 
      else if (gender == "Select Gender") 
      { 
       alert("Please Select a gender"); 
      } 
      else { 
       store(); 
      } 
     } 

形式的HTML:

<form class="form-horizontal" role="form"> 

提交按鈕:

<input type="submit" id="submit" value="Submit" onclick="validate()"> 
+0

那麼你的問題是傳遞表單數據或重定向到其他頁面?你怎麼調用這個函數?如果它在表單的提交處理程序中,請確保您阻止提交默認表單。 – Barmar

+0

我在提交按鈕上使用'onclick'處理程序來調用函數'validate()'來驗證表單數據。驗證後驗證()函數調用這個函數store()' –

+0

'validate'是否阻止提交按鈕的默認操作? – Barmar

回答

0

看一看這個plunker:

https://plnkr.co/edit/P4XqhYciFxZeYlRbWXtd?p=preview

<form class="form-horizontal" role="form"> 
     <textarea rows="4" cols="50" id="comments" placeholder="Enter comments"></textarea> 
     <br /> 
     <select id="gender"> 
     <option value="Select Gender">Select Gender</option> 
     <option value="male">male</option> 
     <option value="female">female</option> 
     </select> 
     <br /> 
     <button type="button" id="submit" onclick="validate()">Go</button> 
    </form> 

我已經更新了重擊器。該頁面正在重定向,您可以看到這些值保存在本地存儲中。它工作正常。

也許您因爲輸入提交而出現問題,我改用了一個按鈕。

相關問題