How to retrieve cityName through javascript?


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
     // the town you want
     var town = $('#my-input-element-id').val();

1 Like