开发者

Submit a form when click on a hyperlink

In my webpage, I want to submit a form in two ways.

  1. On clicking an Image (say Continue)
  2. On clicking a hyper link (which is again an image)

I need to validate my form. See my code below

<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-ti开发者_开发百科le.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>

My form validation is working when clicking on the image (ie First way). But when I clicked on the hyperlink form validation is not working. See my form validation code

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

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


should answer your question: http://www.webdevelopersnotes.com/tips/html/using_an_image_as_a_submit_button.php3


Use

<input type="image"...> 

inside the form and use an onsubmit handler on the form to validate.


'fm' is your form id

Submit form on hyperlink

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

With Image

(Just use <input type="image" instead of <input type="submit"

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜