Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript to clear form field on button click

I have a field called 'inputaddress' which a user types address details into, so they can perform a google map geocode.

What I would like to do is when the user clicks on the 'searchfortheaddress' button, it will perform the geocode but will then clear the 'inputaddress' field.

Could someone perhaps tell me please how I can clear the field.

like image 204
IRHM Avatar asked Jul 19 '11 16:07

IRHM


People also ask

How do you clear a form field?

To clear all the input in an HTML form, use the <input> tag with the type attribute as reset.


3 Answers

document.getElementById("inputaddress").value = '';
like image 180
Barry Kaye Avatar answered Sep 23 '22 23:09

Barry Kaye


Would $('#inputaddress').html(""); or document.getElementById('inputaddress').value="" work?

like image 30
Eamorr Avatar answered Sep 24 '22 23:09

Eamorr


document.getElementById("inputaddress").value = '';
like image 24
psx Avatar answered Sep 22 '22 23:09

psx