Jump to content

alert a variable, error?


NickBomb

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...