2011-11-04 294 views
0

我有很多通過點擊明確的<input type="image">或回車鍵提交的表單。輸入提交按鈕並輸入

使用的代碼是:

<input width="62" type="image" height="22" border="0" onclick="flipSearchButton()" alt="Search" tabindex="9" src="/images/button-search.gif"> 

這些形式現在已經被重新開發,代碼看起來像這樣

<a onclick="javascript:flipSearchButton();" class="button blue right" tabindex="9" href="javascript: submitform(&quot;main&quot;)">Search</a> 

然而,由於變化,同時點擊回車鍵不提交形成。

如何使輸入按鈕提交表單?

形式的輸入和清除按鈕的HTML部分是:

<div class="inline"> 
     <a class="icon blue left" onClick="javascript:resetForm();">Clear</a> 
    </div> 
    <div id="search_clickable"> 
      <a tabindex="14" class="button blue right" href="javascript:flipSearchButton();submitform('main')">Search</a> 
    </div> 
    <div id="search_unclickable" class="disp_none;"> 
      <a class="button blue right" href="">Searching...</a> 
    </div> 



<script type="text/javascript"> 
    function resetForm() { 
     var formObj = document.main; 
     formObj.subCategory.value = ''; 
     formObj.surname.value = ''; 
     formObj.includeSurnameVariants.checked = false; 
     formObj.forenames.value = ''; 
     formObj.forenames.focus(); 
     formObj.includeForenamesVariants.checked = true; 
     formObj.eventYear.value = ''; 
     formObj.eventYearTolerance[3].selected = true;    
     formObj.county.value = ''; 
    } 

    $(document).ready(function() { 
     document.main.forenames.focus(); 
    }); 
</script> 
+0

你在螢火蟲中看到了什麼樣的錯誤 – defau1t

+0

我沒有看到任何錯誤。如果我點擊輸入鍵 – gek

+0

,如果你提供了更多的代碼,我們可以看看這些函數,看看它們是否導致你的問題,這將有所幫助。 – Blazemonger

回答

1

試試這個:

<a class="button blue right" tabindex="9" 
    href="javascript:flipSearchButton();submitform('main')">Search</a> 
+0

這沒有幫助 – gek

1
$('.submitme').keypress(function(e){ 
     if(e.which == 13){ 
     submitform('main'); 
     } 
}); 

添加那麼這個代碼的類submitme添加到輸入字段您希望表單在按下回車鍵時提交 - 這將調用submitform()方法

+0

我在我的提交按鈕中添加了jquery和類,但仍然按下輸入按鈕不提交表單 – gek