How to retrieve cityName through javascript?

How to retrieve cityName through javascript?
0

#1

Hi,

I tried using getElementById to retrieve the input in the form through Javascript but unable to do it correctly.

Could someone point out my syntax error?


#2

You should prevent the default behavior of forms with javascript:

$('#my-form-id').on('submit', function(event){
     // prevents the form from submitting so you can use the information in javascript
     e.preventDefault();
     // the town you want
     var town = $('#my-input-element-id').val();

     console.log(town);
});