Is it possible to trigger the action of a form with a submit button that's outside the form tags? If so, how should this example be rescripted to make the input tag work outside the form tags?


<form name="input" action="html_form_action.asp" method="get">
First name: <input type="text" name="FirstName" value="Mickey" /><br />
Last name: <input type="text" name="LastName" value="Mouse" /><br />
<input type="submit" value="Submit" />


Recommended Answers

All 4 Replies

Here is one example.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <meta name="generator" content=
    "HTML Tidy for Windows (vers 25 March 2009), see">
    <form name="myform" id="myform" action="html_form_action.asp" method="get">
      First name: <input type="text" name="FirstName" value="Mickey"><br>
      Last name: <input type="text" name="LastName" value="Mouse"><br>
      <button onclick="myform.submit();" value="Submit">SUBMIT</button>

A word of caution: using an HTML or javascript reserved word ('input') as an id or name is asking for trouble :(

Also you don't want to give an input within the form a name="submit", when calling the form's submit function as above, as it will get confused for the forms submit method. As a side note (in case it's not obvious) you can do the above example with any type of element that has an onclick event.

I have published an HTML site from my network drive in my office. I need to put a section where people can leave comments. I tried to read on that as I don't know much about HTML. Can someone help me creat a blog kinda stuff for my HTML site?

try form width:auto;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.