2011-05-19 152 views
1

在我的網頁上。我想以兩種方式提交表格。 1)點擊一個圖像(說繼續) 2)點擊超鏈接?(這又是一個圖像)點擊超鏈接提交表格

我需要驗證我的表單。看到我的代碼如下

<table width="989" border="0" align="center" cellpadding="0" cellspacing="0"> 
      <tr> 
      <td width="989" align="center" valign="top" style="text-align:left;"><table align="left" width="989" border="0" cellspacing="0" cellpadding="0"> 
       <tr> 
        <td width="24" align="left" valign="top" background="../images/box-top-tile.jpg"><img src="../images/box-left-top.jpg" width="24" height="24" /></td> 
        <td width="941" align="left" valign="top" background="../images/box-top-tile.jpg"><img src="../images/box-top-tile.jpg" width="24" height="24" /></td> 
        <td width="24" align="right" valign="top" background="../images/box-top-tile.jpg"><img src="../images/box-right-top.jpg" width="24" height="24" /></td> 
       </tr> 
       <tr> 
        <td align="left" valign="top" background="../images/box-left-tile.jpg"><img src="../images/box-left-tile.jpg" width="24" height="24" /></td> 
        <td height="380" align="left" valign="top" bgcolor="#F9F9F9" style="vertical-align:top;"><table border="0" cellspacing="0" width="941" > 
         <tr> 
         <td width="44"></td> 
         <td style="vertical-align:top;"><!-- start left side--> 
          <form name="frm_signup1" action="signuppersonal" onSubmit="return frmvalidate();" method="post"> 
          <table border="0" cellspacing="0" cellpadding="0" width="455" height="380" > 
           <tr> 
           <td class="signup-head" height="50" style="color:#FFFFFF;">&nbsp;Create Your Profile:&nbsp;<span style="font-size:16px">Getting Started</span></td> 
           </tr> 
           <tr> 
           <td class="signup-box" style="padding-bottom:0px;">MY text. 
         <br> 
            <div style="float:left"> 
            <input type="checkbox" name="read" id="id_read" /> 
            I have read and would like to continue</div> 
            <div style="float:right"> 
            <input type="image" src="../images/site/continue.png" border="0" /> 
            <input type="hidden" name="frm_submit" value="1" /> 
            </div></td> 
           </tr> 
           <tr> 
           <td height="50" style="background-image:url(../images/site/box-grey.png); background-repeat:no-repeat"></td> 
           </tr> 
          </table> 
          </form></td> 
          <td width="50"></td> 
         <td width="355" style="text-align:right; vertical-align:top"><img src="../images/site/main-category.jpg" border="1" /> </td> 
         <td width="44"></td> 
         </tr> 
         <tr> 
         <td colspan="5">&nbsp;</td> 
         </tr> 
         <tr> 
         <td colspan="5" align="center"><table border="0" cellpadding="0" align="center" cellspacing="0"> 
          <tr> 
           <td width="30" align="left" style="vertical-align:middle"><img src="../images/site/right-arrow-disabled.png"></td> 
           <td style="border:1px solid #999999; width:300px;"><table border="0" cellspacing="0" cellspacing="0" height="20" > 
          <tr> 
           <td width="20" style="background-color:#CCCCCC"></td> 
          </tr> 
          </table></td> 
         <td width="30" style="text-align:right; vertical-align:middle"><a href="#" onclick="document.frm_signup1.submit();"><img src="../images/site/left-arrow.png" border="0"></a></td> 
         </tr> 
        </table></td> 
       </tr> 
       <tr> 
         <td colspan="5" height="25" style="text-align:center; vertical-align:bottom;" ><span style="font-size:16px; color:#000000;">Your Progress</span></td> 
         </tr> 
       </table></td> 
      <td height="380" align="right" valign="top" background="../images/box-right-tile.jpg"><img src="../images/box-right-tile.jpg" width="24" height="24" /></td> 
      </tr> 
      <tr> 
      <td align="left" valign="top" background="../images/box-btm-tile.jpg"><img src="../images/box-left-bottom.jpg" width="24" height="24" /></td> 
      <td align="left" valign="top" background="../images/box-btm-tile.jpg"><img src="../images/box-btm-tile.jpg" width="24" height="24" /></td> 
      <td align="right" valign="top" background="../images/box-btm-tile.jpg"><img src="../images/box-right-bottom.jpg" width="24" height="24" /></td> 
      </tr> 
     </table></td> 
    </tr> 
    </table> 

我的表單驗證工作時點擊圖像(即第一種方式)。但是,當我點擊超鏈接表單驗證不起作用。 看到我的表單驗證碼

<script type="text/javascript"> 
function frmvalidate(){ 

    if(document.getElementById('id_read').checked == false){ 
     alert('Please select the Checkbox'); 
     return false; 
    } 
    return true; 
} 
</script> 

請幫我

在此先感謝

回答

0

使用

<input type="image"...> 

形式和使用內一個onsubmit處理程序在表單上進行驗證。

0

'fm'是你的表格ID

提交表單上超鏈接

<a href="" onclick="document.getElementById('fm').submit();return false;">Submit</a> 

有圖像

(只需使用<input type="image" instead of <input type="submit"

<input type="image" src="" onclick="document.getElementById('fm').submit();return false;" >