how to get the text input value in javascript

i have written this code , i have a text field and when i enter something in text box and click submit.the value of text box should alert message box.
how to do this? pls help me

here is what i have tried

<form name="input" action="#" method="post" 
    <input type="text" name="cost" value=" ">
</form>

javascript:

   var trlist = document.getElementsByName("cost");
   alert(trlist);

How to get values from textbox and print it in alertbox?

Leave a Comment