2012-09-17 28 views
1

我有一個包含一些輸入字段和提交按鈕的表單。表單應該提交給一個servlet。表單提交按鈕在Firefox中不起作用,但在Chrome或IE中可用

當我點擊提交/返回時,Chrome或IE中的一切都很好,但它在Firefox上什麼也不做。有關這個問題的任何想法?

HTML:

<body> 
    <div align="center"> 
    <form> 

     <table cellpadding ='2' border ='0'> 
     <tr> 
      <td> 
       <label for="Database">Database</label> 
      </td> 
      <td> 
       <input id="database" type="text" onchange="setdirtybit()" name="Database" style="width:200px"></input> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <label for="Script">Script</label> 
      </td> 
      <td> 
       <input id="script" type="text" onchange="setdirtybit()" name="Script" style="width:200px"></input> 
      </td> 
     </tr> 
     </table> 
     <br /> 
      <input type ='submit' value='Submit' onclick='Close()'></input> 
    </form> 
    </div> 
</body> 

的JavaScript:

function Close() 
    { 
     window.returnValue = ""; 
     if(window.dirtyFlag) 
     { 
      document.forms[0].method="post"; 
     document.forms[0].action="/nbreports/updates/"; 
     document.forms[0].submit(); 
      window.returnValue = getValue('database') + '/' + 
         getValue('script') ; 
     } 
     window.close(); 
    } 

    function getValue(varName) 
    { 
     if(document.getElementById(varName) == null) 
      return ""; 
     if(document.getElementById(varName).value == null) 
      return ""; 
     else 
      return document.getElementById(varName).value; 
    } 

    function setdirtybit() 
    { 
     window.dirtyFlag = 1; 
    } 
+3

什麼是'關閉( )'方法嗎?考慮發佈其代碼,將其提煉爲與此問題相關的內容。 – Shmiddty

+0

結合SUBMIT和ONCLICK並不簡單。你需要正確處理事件。 –

+0

此頁面顯示爲彈出窗口。 Close()方法旨在將值返回到父頁面。已添加代碼 – dharmendra

回答

0

把一個標識上的提交按鈕,他們這樣做:

$(document).ready(function(){ 
    $('#submitButtonId').click(function(){ 
     var url = 'myServletUrlHere'; 
     var data = $('form').serialize(); 

     $.ajax({ 
      type: 'POST', 
      url: url, 
      data: data, 
      success: alert("It worked!") 
     }); 
    }); 
}); 
+0

-1這個問題沒有提到jQuery。 – Snuffleupagus

+0

@Snuffleupagus所以呢?他沒有說我不能使用它。我用jQuery給他回答了他的問題。那麼爲什麼拒絕我的回答呢? – leobelones

1
$('#mytextfield').change(function(e) { 
    $('input[type=submit]').focus(); 
}); 
相關問題