2009-08-20 61 views
7

我有一個代碼(見下文),它在Firefox中完美運行:點擊__JL_SAVE按鈕後保存提交的信息,用戶保持同一頁面上。 但在Internet Explorer &歌劇只重定向到索引頁(的index.php),不保存提交的信息。 我能做些什麼來解決這個問題?謝謝。(javascript)onClick =「form.submit();在IE和Opera上不起作用

這裏我的代碼:

<form action="index.php" id="mosForm" method="post" enctype="multipart/form-data"> 

    <fieldset> 
     <legend><?=__JL_ABOUT_MYSELF?></legend> 
     <span class="a" onclick="showHideLegend('about_myself_1')"><?=__JL_EDIT_BLOCK;?></span> 
     <div id="about_myself_descr" style="display: block"><?=__JL_SELF_DESCR;?></div> 
     <div id="about_myself_1" style="display: none"><?php include "html/about_myself_fill.php"?></div> 
     <div id="about_myself_2""><?php include "html/about_myself_show.php"?></div> 
    </fieldset> 

    <fieldset> 
     <legend><?=__JL_ABOUT_MYSELF?></legend> 
     <span class="a" onclick="showHideLegend('type_1')"><?=__JL_EDIT_BLOCK;?></span> 
     <?php if ($typ_block) {?> 
      <?php /* <input type="checkbox" id="jl_type_block" name="jl_type_block" <?php if ($roon_type_block) echo 'checked ';?> /> */ ?> 
      <input type="checkbox" id="jl_type_block" name="jl_type_block" disabled <?php echo 'checked ';?> /> 
      <label for="jl_type_block"><?=__JL_ON_BLOCK?></label> 
     <?php } else { 
      echo __JL_OFF_BLOCK; 
     }?> 

     <div id="about_myself_descr" style="display: block"><?=__JL_SELF_DESCR;?></div> 

     <div id="type_1" style="display : none"> 
      <?php include "html/type.php"?> 
     </div> 
     <?php if ($typ_block) { ?> 
      <div id="type_2"> 
       <?php include "html/type_show.php"?> 
      </div> 
     <?php } ?> 
     </fieldset> 

     <fieldset> 
      <legend><?=__JL_INTEREST?></legend> 
      <span class="a" onclick="showHideLegend('interest_1')"><?=__JL_EDIT_BLOCK;?></span> 
      <?php if ($interest_block) {?> 
       <input type="checkbox" id="jl_interest_block" name="jl_interest_block" disabled <?php echo 'checked ';?> /> 
       <label for="jl_interest_block"><?=__JL_ON_BLOCK?></label> 
      <?php } else 
       echo __JL_OFF_BLOCK; 
      ?> 
      <div id="interest_descr" style="display:block"><?=__JL_INTEREST_DESCR;?></div> 
      <div id="interest_1" style="display:none"> 
       <?php include "html/interest.php"?> 
      </div> 
      <?php if ($interest_block) { ?> 
       <div id="interest_2"> 
       <?php include "html/interest_show.php"?> 
       </div> 
      <?php } ?> 
     </fieldset> 


      <input type="submit" name="save" value="__JL_SAVE" onClick="mosForm.submit();" /> 
      <input type="hidden" name="option" value="com_joomlove" /> 
      <input type="hidden" id="task" name="task" value="save_info" /> 
      </form> 

完整源代碼可用h ERE:http://narkoz.pastebin.com/f4f036f5

回答

8
  1. 如果你不改變形式,爲什麼使用JavaScript提交表單的行爲?你已經在一個提交按鈕。

  2. 您應該嘗試給出表單name =「mosForm」,而不僅僅是id =「mosForm」,以便可以找到該事件處理函數的DOM引用。

+1

同意並同意。 – Funka 2009-08-20 03:26:44

+1

你也可以使用「this.form.submit()」來引用按鈕中的表單... – Funka 2009-08-20 03:28:14

10

您應該真的在FORM的「submit」事件處理程序中執行任何與提交相關的邏輯,而不是在「單擊」其中一個FORM元素。例如:

<form ... onsubmit="return validateForm(this);"> ... </form> 

這應該確保基於鍵盤的提交通過你的處理程序;它還使您能夠通過從事件處理程序返回falsy值來阻止表單提交。另一方面,任何真實價值將自動提交表格。

+1

此方法還允許在javascript被禁用或不可用的情況下提交。 – 2009-11-26 08:01:13

+0

適用於我,當我在方法體中使用'onsubmit =「validateForm(this)」'和'return true'。 – Simon 2015-04-23 05:53:44

1

當你有:

<form method="post" action="somefile.php" name="form" id="form"> 
<button type="button" name="submit" onclick="$('#form').submit()">go</button> 
</form> 

是否在IE8,歌劇,鉻工作,但不能在Firefox(14):

Firefox有一個問題:name="submit"。當您在name="submit_ff"(或其他)中更改name屬性時,它也可以在Firefox中使用。