Q:

alerting textbox through javascript

very simple question! i was wondering how to use javascript to alert something in my textbox...not sure what i'm doing now is not working. heres the function
function alertNow(comment){
alert(comment);
}

now here is the textbox
<input type = 'text' name = 'txt_comment'>
<button onClick = alertNow(txt_comment.value) value = "Submit Comment"></button> 

sure this is doable, i did it before but i just forgot some syntax prob. any ideas? thanks!

A:

You are missing quotations. Also use the ID instead of name.
<input type = 'text' name = 'txt_comment' id='txt_comment'>
<button onClick = 'alertNow(txt_comment.value)' value = "Submit Comment"></button> 

Also better to use, document.getElementById like below
 <button onClick = 'alertNow(document.getElementById("txt_comment").value)' value = "Submit Comment"></button> 

