Reputation: 476
All,
I feel like this question has been asked in many ways, and answered in just as many so I apologize. I am trying to take user input via HTML forms, and print the output back to the screen though a javaScript function.
<form id="loginInfo" >
<input id="userName" type="text" name="user" size="40" placeholder='Username' />
<input id="loginButton" type="image" value="submit" src="\Images\login.png" onclick="loginButtonClick()" alt="submit" height="26" />
<script>
var username = document.forms.loginInfo.userName.value;
function loginButtonClick() {
alert(username);
}
</script>
I think my issue lies in the fact that my button is an image, and I may be doing something wrong in that arena. Any help would be appreciated.
Upvotes: 0
Views: 7981
Reputation: 7769
Just put var username = document.forms.loginInfo.userName.value;
inside loginButtonClick()
function
So the final script will be:
<script>
function loginButtonClick() {
var username = document.forms.loginInfo.userName.value;
alert(username);
}
</script>
Upvotes: 1