Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

retrieving text field value using javascript

Tags:

javascript

I want to retrieve textfield value using javascript. suppose i have a code like:

 <input type='text' name='txt'>

And I want to retrieve it using javascript. I call a function when a button is clicked:

<input type='button' onclick='retrieve(txt)'>

What coding will the retrieve function consist of?

like image 875
Sanket Raut Avatar asked Feb 22 '11 04:02

Sanket Raut


1 Answers

You can do this:

Markup:

<input type="text" name="txt" id="txt"/>
<input type="button" onclick="retrieve('txt');"/>

JavaScript:

function retrieve(id) {
    var txtbox = document.getElementById(id);
    var value = txtbox.value;
}
like image 151
Andrew Hare Avatar answered Sep 28 '22 22:09

Andrew Hare