Is there a way to make the below script pass the javascript values to the url of the href link?
<script type="text/javascript">
function geoPreview(lat,long) {
var elemA = document.getElementById("lat").value;
var elemB = document.getElementById("long").value;
window.location.href = "http://www.gorissen.info/Pierre/maps/googleMapLocation.php?lat=elemA&lon=elemB&setLatLon=Set";
}
</script>
Try this:
Do you mean include javascript variable values in the query string of the URL?
Yes:
This is rather over-complicated but will make sense to the inexperienced programmer. In a url, you can include a ‘#’ sign, and anything else can go after that while just going to that page. So you can use js:
Then in the other page use JavaScript to read the url and take what information is necessary.
NOTE: the js above is not tested.
Summary
With either string concatenation or string interpolation (via template literals).
Here with JavaScript template literal:
Both parameters are unused and can be removed.
Remarks
String Concatenation
Join strings with the
+
operator:String Interpolation
For more concise code, use JavaScript template literals to replace expressions with their string representations. Template literals are enclosed by
``
and placeholders surrounded with${}
:Template literals are available since ECMAScript 2015 (ES6).
Try this:
To put a variable in a string enclose the variable in quotes and addition signs like this:
Just remember that one rule!