| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/es/docs/Web/API/HTMLFormElement | [Back] [Original] |
Get to know MDN better
Esta pgina ha sido traducida del ingls por la comunidad. Aprende ms y nete a la comunidad de MDN Web Docs.
This feature is well established and works across many devices and browser versions. Its been available across browsers since julio de 2015.
Los elementos FORM comparten todas las propiedades y mtodos de los otros elementos HTML descritos en el captulo del elemento. Tambin tienen la interfaz especial HTMLFormElement.
Esta interfaz proporciona mtodos para crear y modificar los elementos FORM usando el DOM. El siguiente ejemplo muestra como crear un nuevo formulario, como modificar sus atributos y enviarlo:
// Crea un formulario
var f = document.createElement("form");
// Lo aade en el cuerpo ('body') del documento
document.body.appendChild(f);
// Aade los atributos de accin y mtodo
f.action = "/cgi-bin/some.cgi";
f.method = "POST"
// Llama el mtodo de enviar el formulario
f.submit();
Adems, el siguiente documento HTML muestra como se puede extraer informacin de un formulario y cambiar algunos de sus atributos.
<title>Ejemplo de formulario</title>
<script type="text/javascript">
function getFormInfo() {
var info;
// Obtiene una referencia utilizando la coleccin de formularios
var f = document.forms["formularioA"];
info = "f.elements: " + f.elements + "\n"
+ "f.length: " + f.length + "\n"
+ "f.name: " + f.elements + "\n"
+ "f.acceptCharset: " + f.acceptCharset + "\n"
+ "f.action: " + f.action + "\n"
+ "f.enctype: " + f.enctype + "\n"
+ "f.encoding: " + f.encoding + "\n"
+ "f.method: " + f.method + "\n"
+ "f.target: " + f.target;
document.forms["formularioA"].elements['tex'].value = info;
}
// Se pasa la referencia al formulario desde el
// atributo al hacer clic ('onclick') del botn con la ayuda de este.formulario ('this.form')
function setFormInfo(f) {
f.method = "GET";
f.action = "/cgi-bin/evil_executable.cgi";
f.name = "totally_new";
}
</script>
<h1>Ejemplo de formulario</h1>
<form name="formularioA" id="formularioA"
action="/cgi-bin/test" method="POST">
<p>Haga clic en "Info" para ver informaciones de este formulario.
Haga clic en "Set" para cambiar los parmetros y otra vez en "Info" para ver los efectos</p>
<p>
<input type="button" value="Info"
>
<input type="button" value="Set"
>
<input type="reset" value="Reset">
<br>
<textarea id="tex" >
</p>
</form>
.elements devuelve una coleccin de todos los controles que hay en el formulario FORM.
.length devuelve la cantidad de controles que hay en el formulario
.name devuelve el nombre del formulario actual en forma de cadena.
.acceptCharset devuelve una lista del conjunto de caracteres soportados para el actual elemento FORM.
.action obtiene/configura la accin del elemento FORM.
.enctype gets/sets the content type of the FORM element.
.encoding gets/sets the content type of the FORM element.
.method obtiene/configura el mtodo HTTP utilizado para enviar el formulario.
.target obtiene/configura el objetivo de la accin (i.e., the frame to render its output in).
submit() manda el formulario.
reset() restaura el formulario, lo devuelve al estado inicial.
This page was last modified on 17 dic 2024 by MDN contributors.
formBeforeUnloadEventDOMStringMapErrorEventHTMLAnchorElementHTMLAreaElementHTMLAudioElementHTMLBRElementHTMLBaseElementHTMLBodyElementHTMLButtonElementHTMLCanvasElementHTMLDListElementHTMLDataElementHTMLDataListElementHTMLDialogElementHTMLDivElementHTMLDocumentHTMLElementHTMLEmbedElementHTMLFieldSetElementHTMLFormControlsCollectionHTMLFrameSetElementHTMLGeolocationElementHTMLHRElementHTMLHeadElementHTMLHeadingElementHTMLHtmlElementHTMLIFrameElementHTMLImageElementHTMLInputElementHTMLLIElementHTMLLabelElementHTMLLegendElementHTMLLinkElementHTMLMapElementHTMLMediaElementHTMLMenuElementHTMLMetaElementHTMLMeterElementHTMLModElementHTMLOListElementHTMLObjectElementHTMLOptGroupElementHTMLOptionElementHTMLOptionsCollectionHTMLOutputElementHTMLParagraphElementHTMLPictureElementHTMLPreElementHTMLProgressElementHTMLQuoteElementHTMLScriptElementHTMLSelectElementHTMLSourceElementHTMLSpanElementHTMLStyleElementHTMLTableCaptionElementHTMLTableCellElementHTMLTableColElementHTMLTableElementHTMLTableRowElementHTMLTableSectionElementHTMLTemplateElementHTMLTextAreaElementHTMLTimeElementHTMLTitleElementHTMLTrackElementHTMLUListElementHTMLUnknownElementHTMLVideoElementHashChangeEventHistoryImageDataLocationMessageChannelMessageEventMessagePortNavigatorPageRevealEventPageSwapEventPageTransitionEventPluginPluginArrayPromiseRejectionEventRadioNodeListTimeRangesUserActivationValidityStateWindowWorkletGlobalScopeYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |