How to Pass a Parameter to HTML

How to pass the parameters from one html page to another

Your fields need to have name attributes to pass values as the id will not do this.

The javascript DOM element selectors (document.getElementById('ManagerId').value, etc.) in index.js are looking for elements on page 2 that don't appear to exist. You'll have to do a little more to actually pull the the parameters from the URL using window.location.search(). See: How to obtain the query string from the current URL with JavaScript?

Open new HTML page via javascript and pass parameters

Your sending the entire object to the page, while you should send just its value.
Use this code to get the value of an input :

var value = document.getElementById("input").value;

Then, it's really simple to redirect to other page sending data via URL. You just need to redirect adding a parameter like this :

window.location.href = "searchresult.html?city="+value;

How to pass parameters from script to html form value

You should change showPosition to this:

    <script>
function showPosition(position) {
let hData = returnH(position);
let wData = returnW(position);

x.innerHTML = "Latitude: " + hData +
"<br>Longitude: " + wData;
mapboxgl.accessToken = 'My Token';
var map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/mapbox/streets-v11', // style URL
center: [position.coords.longitude, position.coords.latitude], // starting position [lng, lat]
zoom: 18 // starting zoom

});

document.querySelector("#hValue").value = hData;
document.querySelector("#wValue").value = wData;
}
function returnH(position) {
return position.coords.latitude;
}
function returnW(position) {
return position.coords.longitude;
}
</script>

and also change form to this:

<form action=".." method="POST">
<input type="hidden" id="hValue" />
<input type="hidden" id="wValue" />
</form>

How to pass variables into an HTML body

The HTML must be a string (text), and you need to build the HTML with a text formula. Text strings in JavaScript are put together, (concatenated) with a plus sign:

var tableHTML = '<table style="width:100%">' + //Note single quotes on ends
"<tr><td>Calories</td><td>" +
calories +
"</td></tr>" +
"<tr><td>Calories From Fat</td><td>" +
caloriesFromFat +
"</td></tr>" +
"<tr><td>PolyUnsaturated</td><td>" +
polyFat +
"</td></tr>" +
"</table>";

If double quotes are used in the HTML attribute, then use single quotes on the ends of the string.
Then just use the variable name for the email HTML:

htmlBody: tableHTML


Related Topics



Leave a reply



Submit