How to retrieve cityName through javascript?

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?

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);
});
1 Like