How to make the below script pass the javascript values to the url of the href link?
<script type="text/javascript">
function myFunction(name) {
var elemA = name;
window.location.href = "view.php?search=elemA";
}
</script>
You can attach a variable to a string like this. You may have to use the function encodeURIComponent to avoid errors with whitespaces etc.
function myFunction(name) {
var elemA = name;
window.location.href = "view.php?search=" + encodeURIComponent(elemA);
}
encodeURIComponent, applied on the parameter value only.
window.location.href = "view.php?search=" + elemA;`)