Tengo un formulario y quiero agregar una variable javascript dentro del valor="". value="embedurl" Soy nuevo en agregar una variable javascript dentro de html, hasta ahora, todas las soluciones que encontré en Google no funcionan. ¿Como hacer esto? Gracias.
<form id="landing2" action="https://example.com/post10/" method="post"> <input type="hidden" name="name" value=" var embedurl "> <input type="submit"> </form> <script> var embedurl ="https://" + document.location.host + "/embed" + window.location.pathname; document.getElementById('landing2').submit(); </script>Prueba esto ,
var embedurl ="https://" + document.location.host + "/embed" + window.location.pathname; document.getElementsByName("name")[0].value = embedurl; // here you need to set the input value document.getElementById('landing2').submit();Si desea agregar un valor de javascript, debe hacerlo por javascript.
Primero, debe obtener el elemento de entrada dom, luego establecer el valor
var form = document.getElementById("landing2"); var input = form["name"]; input.value = embedurl;