html/javascript how to display user input with a method on button click? -
i'm trying alert window display first , lastly name user inputs after click "submit". i'm trying using methods in javascript, can't display after user clicks button.
here code:
<html> <head> <meta charset = 'utf-8'> <title>form</title> <script type = 'text/javascript'> var firstname; //first name var lastname; //last name function getfirstname() { //get first name homecoming document.getelementbyid("first_name").value; } function getsecondname() { //get lastly name homecoming document.getelementbyid("last_name").value; } function display() { //get names , display them firstname = getfirstname(); lastname = getlastname(); window.alert(firstname + lastname); } document.getelementbyid("submit").onclick = display(); </script> </head> <body> <form id='form' method = 'post'> <p> first name: <input type='text' id = "first_name"/></p> <p> lastly name: <input type='text' id = "last_name"/> </p> <p><input id ="submit" type = "button" value = 'clickme' /></p> </form> </body> </html>
http://jsfiddle.net/wqymjl32/
<form id='form' method = 'post'> <p> first name: <input type='text' id = "first_name"/></p> <p> lastly name: <input type='text' id = "last_name"/> </p> <p><input id ="submit" type = "button" onclick="display()" value='clickme'/></p> </form>
slight alter html, onclick attribute / event added submit button.
var firstname; //first name var lastname; //last name function getfirstname() { homecoming document.getelementbyid("first_name").value; } function getsecondname() { homecoming document.getelementbyid("last_name").value; } function display() { firstname = getfirstname(); lastname = getsecondname(); window.alert(firstname + lastname); document.getelementbyid("form").submit(); }
slight alter javascript phone call getsecondname instead of getlastname
javascript html
No comments:
Post a Comment