0

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>

2 Answers 2

3

You are writing getElementsById, which isn't a function.

Try it singular, not plural:

document.getElementById("name")
Sign up to request clarification or add additional context in comments.

Comments

0

     <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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.