Reputation: 112
So here is my code
<script>
function ls() {
var text = document.getElementById("name").value;
document.cookie = "username=" + text + ";";
document.getElementById("name").innerHTML = text;
}
</script>
<p id="name"><p>
<input type="text" id = "textbox"> <br/>
<input type="Submit" value = " Submit " onClick = "ls()">
And when i run it and enter a value into the text box the press submit it creates the cookie but with a "undefined" as the value. Also the "name" text is set to "undefined"
Anyone know what im doing wrong?
Upvotes: 0
Views: 503
Reputation: 7184
You confused your id's. Use textbox instead of name.
var text = document.getElementById("textbox").value;
Upvotes: 2