Aquí esta el código
Código HTML:
<html> <head> <title>Enviando información por post</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <script type="text/javascript" language="javascript"> var form = document.createElement("form"); // crear un form with(form) { setAttribute("name", "myform"); //nombre del form setAttribute("action", ""); // action por defecto setAttribute("method", "post"); // method POST } var input = document.createElement("input"); // Crea un elemento input with(input) { setAttribute("name", "theInput"); //nombre del input setAttribute("type", "hidden"); // tipo hidden setAttribute("value", ""); // valor por defecto } form.appendChild(input); // añade el input al formulario document.getElementsByTagName("body")[0].appendChild(form); // añade el formulario al documento window.onload=function(){ var my_links = document.getElementsByTagName("a"); for (var a = 0; a < my_links.length; a++) { if (my_links[a].name=="post") my_links[a].onclick = function() { document.myform.action=this.href; document.myform.theInput.value=this.title; document.myform.submit(); return false;} } } </script> <h3>Enviando información por post</h3> <a href="ejemplo_post.php" name="post" title="Este valor se enviará por post" >Pulsa aquí </a> para hacer POST<br> También puedes <a href="ejemplo_post.php" name="post" title="Este valor también se envía por post" >pulsar aquí</a> para hacer otro POST<br> Esto es un<a href="ejemplo_post.php" > link normal</a> </body> </html>
Se que en esta linea
Código:
toma como objeto el dato del enlace document.getElementsByTagName("a");