Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

219
Views
How to Add javascript variable inside html attribute

I have a form and I want to add javascript variable inside the value="". value="embedurl" I am new to adding javascript variable inside html, so far, all of the solutions that i found on google is not working. How to do this? Thanks.

<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>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Try this ,

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();
about 4 years ago · Juan Pablo Isaza Report

0

If you want to add a javascript value, you must do it by javascript.

First, you need to get the dom input element, then set the value

var form = document.getElementById("landing2");
var input = form["name"];

input.value = embedurl;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!