Unfortunately I cannot change the ID of an input, and would like to use JavaScript to change its value.
<input id="name-with-annoying-hyphens" type="number" />
<script>
document.getElementById(['name-with-annoying-hyphens']).value = "10";
</script>
I cannot get rid of the three hyphens as the ID is so deeply grandfathered into everything. I also can't just put a value definition because the JavaScript has dynamic values. I've distilled things to get to the point.
Does anybody have a workaround or any experience with this?
I'll post the full script of what I'm trying to do.
Query string: {url}?amount=100
<script type="text/javascript">
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) { return pair[1]; }
}
return(false);
}
</script>
<input id="name-with-annoying-hyphens" type="number" />
<script>
document.getElementById(['name-with-annoying-hyphens']).value = getQueryVariable("amount");
</script>
It would make my week if somebody knew of a work around. :(