Today we want to discuss a very old HTML concept called the form tag which allows for the processing of interactive input from the user in the form of textboxes and checkboxes and radio buttons and buttons to transfer information from one webpage to another, somewhere.
For clarity, today, we only use buttons, and you may ask, โWhat good are buttons on their own for imparting information?โ โฆ and will ignore the obvious answer that a button press anywhere, depending on the event logic, can mean so much โฆ after all, we all envisaged the disaster of a nuclear holocaust envisaging the press of one button โฆ no, we want to talk about the idea that you can have more than one input tag with type=โsubmitโ โฆ and this was not always the case, because in the early days of HTML there was the one submit button allowed on one HTML form โฆ now you can even have more than one form โฆ but this is for another day.
Anyway, you might still ask, anyway, โIgnoring the huge event logic possibilities of a button press (because you are not trying to trick me here), what good are buttons on their own for imparting information?โ โฆ well, it means on the callback โฆ and today we just callback the same HTML code (via the formโs action= designation of itself, today) โฆ as we often like to do at this blog, by the way โฆ we can compartmentalize via the GET (in our formโs method case โฆ for starters, with POST weโd need Ajax or a server language, and remember we are trying to keep things more basic here) parameters in the callback URL (stored in โJavascript DOM landโ as document.URL) according to the value of that submit button whose name becomes that GET parameterโs name โฆ so that for an HTML formโs submit button like โฆ
<input type='submit' title='Submit of form to an embedded iframe' onclick='cif();' name='submitiframe' id='submitiframe' value='Validate and Iframe'></input>
โฆ its contributing part of the callback URL, in our code, is โฆ
... ?submitiframe=Validate+and+Iframe ...
โฆ and so we can, in Javascript, at the onload eventโs code โฆ have an else if statement like โฆ
} else if (document.URL.indexOf('iframe=') != -1) {
// do something here
}
โฆ to have a good compartmentalizing of โactionโ segments of code that is quite readable and understandable.
If the case is not clear โฆ please tee up a liverun with the HTML programming source code multiple_form_submit_buttons
html โฆ or else please try some HTML code yourself โฆ the hardest concept here today is the embedding of an iframe in a hierarchical way (note the Javascript DOM manipulation of the formโs target= designation, as you examine the downloadable code above), and so for clarity we preface any iframe by a current client (ie. Javascript) timestamp, so you know who inherits who etcetera etcetera etcetera.
Now even after all this, you may want to say, โSo what โฆ an HTML a tag link can do all this. โฆ to which we say โฆ thatโs true โฆ good to know there is more than one way to โskin a catโ โฆ meowwwwwwww! โฆ โno animals were harmed in the making of this tutorialโ.
In fact you could go on and on and on with possibilities for the equivalent means by which to achieve the ends we have here with our HTML, such as using an input type=โbuttonโ or in HTML5, a button tag, and all these and more and more and more and more are worth exploring, and trying, yourself, or by researching the subject. One day, in a real bind, with cross-browser issues, you may need that extra method, to make things work for all the platforms?!
Did you know?
With an HTML input type=โsubmitโ (submit button), there is nothing stopping you storing more than just the โfront lookโ of the button in its value= parameter. If you want to do this, but there is no way you want to show that โdataโ as the โfront lookโ of the button, perhaps it really should be an input type=โhiddenโ piece of data, or you should hide it โฆ via style=โdisplay:none;โ โฆ Javascript DOM store data to it via document.getElementById([itsID]).value=[myData]; โฆ and, conditionally perhaps, click it via Javascript, via document.getElementById([itsID]).click(); method.
If this was interesting you may be interested in this too.
18 Responses to HTML Form Multiple Submit Buttons Primer Tutorial