Javascript to clear a form field when a button is clicked

I have a field called 'inputaddress' in which the user enters the address data, so they can execute the google map geocode.

What would I like to do, when the user clicks the "searchfortheaddress" button, he will execute the geocode, but then clear the "inputaddress" field.

Maybe someone can tell me how I can clear the field.

+7
source share
4 answers
document.getElementById("inputaddress").value = ''; 
+22
source

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

+4
source
 document.getElementById("inputaddress").value = ''; 
+2
source

I assume the u id field of your addr input address is just add this code to the onclick event of your searchforaddress button

 document.getElementById('addr').value=""; 

like this (i guess ur searchforaddress button)

  document.getElementById('searchforaddress').onclick=function() { document.getElementById('addr').value=""; }; 
0
source

All Articles