Jump to content

alert a variable, error?


Recommended Posts

My script does'nt work as I want to...This is my java script:

	var name = "";	function alertname() {	name = document.getElementById('textname');	alert('welcome, '+ namn +'!');	}

This is the HTML:

<input type="text" value="" size="20" name="textname" id="textname" maxlength="20"><br><br><input type="button" id="buttonbörjaspela" value="Go!" onClick="alertname()">

The alert says:Welcome, [object HTMLInputElement]!I have no idea what's wrong...Please help...

Link to comment
Share on other sites

the problem was at the part in red color.To retrieve the text from the field you should use .value function alertname() { var name = document.getElementById('textname'); alert('welcome, '+ name.value +'!'); }

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...