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 'sear开发者_运维百科chfortheaddress' 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.
document.getElementById("inputaddress").value = '';
Would $('#inputaddress').html("");
or document.getElementById('inputaddress').value=""
work?
document.getElementById("inputaddress").value = '';
i am assuming that u id your input address field addr
just add this code to the onclick
event of your searchforaddress
button
document.getElementById('addr').value="";
like this (i am assuming is of ur searchforaddress
button is searchforaddress
)
document.getElementById('searchforaddress').onclick=function() {
document.getElementById('addr').value="";
};
精彩评论