Reputation: 451
I am simply trying to get the user name via an html button then append a string to it before submitting the concatenated string to a website. But the string doesn't seem to change
<form action="website.com" method="POST">
<input name="login" id="name" value="username" />
<script>
var str1 = document.getElementsById("name").value;
var str2 = " Goodbye";
document.getElementsById("name").value = str1.concat(str2);
</script>
<button id="button" >press the button</button>
Upvotes: 0
Views: 42
Reputation: 1389
<form action="website.com" method="POST">
<input name="login" id="name" value="username" />
</form>
<script>
function getName() {
var str1 = document.getElementById("name").value;
var str2 = " Goodbye";
document.getElementById("name").value = str1.concat(str2);
}
</script>
<button id="button" onclick="getName()">press the button</button>
Upvotes: 0
Reputation: 5516
You are writing getElementsById
, which isn't a function.
Try it singular, not plural:
document.getElementById("name")
Upvotes: 3