The younger brother encountered a problem. I hope that in the struts framework, the input information on my page is verified using js. When I find that the information filled by the user is incomplete, an alert prompt will pop up, but I hope that the page will not be submitted at this time, but the page will always be submitted to the following Action, and the page will be flashed. How can this problem be solved, which of the following experts can advise? Thank you.
<Form action = 'actionname' method = 'post' name = 'formname'>
You can change the user submit button to not submit, and then use formName. submit () to submit the page to action if the data is valid after the judgment in. js.
Alas
This is the same as normal,
<Script>
Function check ()
{}
</Script
<Form action = 'actionname' method = 'post' name = 'formname' onSubmit = "return check ()">
...
</Form>
Write a function check () to test,
Write another function to submit it:
If (check () = true ){
FormName. submit ();
}
Put it in the onClick () event of the button.
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN"
Http://www.w3.org/TR/html4/loose.dtd>
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> untitled document </title>
</Head>
<Script language = "javascript">
//
Function ch ()
{
If (document. form1.textfield. value = "" | document. form1.textfield2. value = "")
{
Alert ("incomplete information ");
Return false;
}
Return true;
}
//
</Script>
<Body>
<Form name = "form1" method = "post" action = "2.asp" onSubmit =" return ch () ">
<P> username:
<Input type = "text" name = "textfield">
</P>
<P> password:
<Input type = "text" name = "textfield2">
</P>
<P>
<Input type = "submit" name = "Submit" value = "submit">
<Input type = "reset" name = "Submit2" value = "reset">
</P>
</Form>
</Body>
</Html>