2013-05-08 66 views
0

所以我在我的父窗口的「的onclick」按鈕屬性使用此代碼:父提交功能提交的iFrame格式不驗證輸入類型

window.frames['sample'].document.forms['sample_sheet'].submit(); 

最初(並通過HTML內置的檢查)iframe的提交按鈕,單擊時,如果我在數字輸入字段中鍵入一個字母並嘗試提交,會給我一個驗證錯誤。例如:

<input type="number" /> 

因此,如果我在該輸入中鍵入「RG」,當我嘗試提交時,我會得到「請輸入一個數字」。

但是,使用上面提供的父窗口按鈕的提交函數,表單將會提交,無論如何,我也有一個HTML min ='0'屬性,通過submit函數被忽略如果我輸入一個負數,它會提交沒有HTML檢查)。我確實需要HTML驗證才能在提交之前工作!爲什麼它現在不能工作,我該如何驗證?在父窗口

enter image description here

HTML

<iframe src="sample/" 
      frameborder="" name="sample" id="sample" class="contentiframe"></iframe> 

<a onclick="window.frames['sample'].document.forms['sample_sheet'].submit();" data-transition="flip" data-theme="" data-icon="check"> 
        Submit 

FORM HTML中的iframe

<form id="sample_sheet" name="sample_sheet" action="php/upload.php" method="post"> 
<table>   ....... 
<tr> 
      <td>Sample Sequence</td> 
      <td><input type="number" name="sample_no" id="sample_no" /></td> 
</tr> 
<tr> 
      <td>Waste Weight</td> 
      <td><input type="number" step="any" min="0" name="waste_wt" id="waste_wt" /></td> 
     </tr> 
</table> 
<!--<input type="submit" value="Submit" />--> 
</form> 

回答

1

你的回調函數中使用event.PreventDefault()?這將停止點擊按鈕上的任何默認操作。

+0

我需要一點點更多的代碼比這,看看發生了什麼事情。但這是一個很好的開始。防止默認。 – ayesham 2013-05-08 20:01:53

+0

不確定你的意思,但我用代碼編輯了我的問題。 – jflay 2013-05-08 20:54:12

+0

我從來沒有實現任何PreventDefault函數 – jflay 2013-05-09 17:20:01