Form form inside button implementation Location.href jump

Source: Internet
Author: User

These two days in the erection of an earlier PHP application, found that there are several buttons in IE click Effect, in Chrome, Firefox click does not respond. The problem comes, then immediately F12 pull out the artifact to start debugging, the following HTML code to paste out:

<HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Form form Location.href Jump failure Reason</title></Head><Body><formAction= "Main.php?action=serach"Method= "POST">  <TDwidth= "$"Align= "Right"nowrap= "NoWrap"class= "F_bold">Screening:</TD>  <TDnowrap= "NoWrap"><SelectID= "id"style= ' cursor:Hand '>      <optionselected= "Selected"value= "0">All</option>      <optionvalue= "2">Enable</option>      <optionvalue= "1">Deactivate</option>    </Select>    &nbsp;&nbsp;</TD>  <TDwidth= "$"Align= "Right"nowrap= "NoWrap"class= "F_bold">Search:</TD>  <TDnowrap= "NoWrap"><Selectname= "Vip_name"OnChange= "return C_key ();" >      <optionvalue= "0">Account:</option>    </Select>  <TDwidth= "67%"class= "F_bold"><inputtype= "text"name= "Key"class= "INPUT1"  />    &nbsp;&nbsp;    <inputtype= "Submit"value= "OK"name= "B1"class= "Button_b"style= "Width:60;height:22" ;></TD>  <TDwidth= "67%"class= "F_bold"><spanID=FM22>    <Buttonclass= "Button_b"OnClick= "javascript:location.href= ' Main.php?action=user_add ';"  >Add a Member</Button>    </span></form></Body></HTML>

This form has two buttons, one is the search button, one for the Add Member button, in IE, two buttons to achieve normal function, Chrome, Firefox "Add Member" this button's jump code has been unsuccessful, at first, the event code generated by the browser is not compatible, Two or three ways to change the problem is not solved:

<!--method One----
<Script> functionOpenURL (str) {location.href=str; } </Script> <Buttonclass= "Button_b"OnClick= "OpenURL (' Main.php?action=user_add ');" >Add a Member</Button>
<!--method Two--
<button class= "Button_b" onclick= "window.location.href= ' Main.php?action=user_add ';" > Add a member </button>

Later found that click on the button after the page has a refresh (jump), jump to the page is: Main.php?action=serach, because in the actual debugging when the page is nested in the IFRAME, jump Link has not been noticed, is through the fiddler grabbed the bag before notice, This is understood, after clicking the Add Member button, the actual execution is the form submission, which is the problem. To make the form do not commit, just return false to OK. The modified code

<class= "Button_b"  onClick= "javascript:location.href= ' main.php?" Action=user_add '; return false; "  > Add member </button>

Smooth execution.

Summarize the question:

Buttons that are not related to the form should not actually be included in the form (the code is not written by me)

IE Browser first executes LOCAITON.HREF, will not submit the form, and Chrome, Firefox may be waiting for the event code after the execution of the jump code (not tested, do not know the correct statement)

Form form inside button implementation Location.href jump

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.