I've a form and I've a submit button in it.
What I want is to place the submi开发者_C百科t button outside the tag (because of design issues) but still want to be able to submit the form when I click on it.
Create a javascript either function or add it directly to the submit button.
<input type='button' value='submit' onClick="document.formName.submit()" >
-- or --
<a href="javascript:document.formName.submit();">Click Here</a>
if you use jquery,
<form name="getform" id="theform" target="/baby/index.html">
...
</form>
<button value="submit" onclick="$('#theform').submit();" />
There is no reason to move anything form related out of the form element. If the form element messes up your design, you should solve this using CSS:
form
{
margin: 0px;
padding: 0px;
}
I agree with others answers. This is just one more possibility using <button>
instead <input>
. Please take a look on my example.
<html>
<head>
<script>
function myFunction(form_id)
{
document.getElementById(form_id).submit();
}
</script>
</head>
<body>
<form id="id_form" method="post" action="handler.php">
Username <input type="text" name="Username"></input>
Password <input type="password" name="Password"></input>
</form>
<form id="otherid_form" method="post" action="otherhandler.php">
Guestname <input type="text" name="Username"></input>
</form>
<button onclick="myFunction('id_form')"> submit text</button>
...more more stuff if you want...
<button onclick="myFunction('otherid_form')"> submit text</button>
</body>
</html>
With HTML5, you can simply do :
<form id="theForm">
...
</form>
<button type="submit" form="theForm">OK</button>
精彩评论