Link to home
Start Free TrialLog in
Avatar of Whing Dela Cruz
Whing Dela CruzFlag for Anguilla

asked on

How to obtain a message from a textbox?

Hi experts, I have a button name "click me" I want to show the value of my textbox when I click this button. The value of my textbox is "Hello world" I want this to appear on the messagebox. Sorry, but i am a new beginner of HTML5. Tnx!
<html>
<body>
<form 
action="">
First name :<input type="text" 
name="iMsg" 
value="Hello world">

</form>

<button 
	> Click Me
</button>

</body>

</html>

Open in new window

SOLUTION
Avatar of Duy Pham
Duy Pham
Flag of Viet Nam image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Whing Dela Cruz

ASKER

Hi Duy Pham, its working. But i need to add another text value to place into another line. My first text value is cow and my second text value is dog. I want to get this in different lines. Also I need to put a title on the message box.  
<script>
	function myFunction() 
	{
    		var x = document.getElementsByName("iMsg")[0].value + " first";
		alert(x);
		
	}
</script>

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@Michel:  Thanks. You were right that getElementByName does not exists.
Hi experts, this is my code but it doesn't work please correct.
<script>
	function myFunction() 
	{
        var x = document.getElementsByName("animal")[0].value;
        var y = document.getElementsByName("animal")[1].value;
        alert('x + \n y');		
	}
</script>

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Duy Pham, its now working...