-1

I am trying to create a google web map using google maps v3, and I want to include a function whereby when the user selects a time (e.g. 6AM) in a select option (dropdown list), the markers fitting this condition will appear. However, when I try this, google chrome's console only detects the default selected option and doesn't change the value as selected accordingly. (you can say it doesn't do a postback I suppose?) I looked around and found a solution from this question, and added the codes in accordingly

 <select id="ddlTime" onchange="this.form.submit()"> ...

but this is what was returned in my console

Uncaught TypeError: Cannot read property 'submit' of null

Community
  • 1
  • 1
user3763216
  • 489
  • 2
  • 10
  • 29

1 Answers1

1

this does not reference the select when used in that manner. As you've tagged jQuery, here's how to do it:

$('#ddlTime').change(function() {
    $(this).closest('form').submit();
});

If you would prefer to stick with the onchange attribute (which I would advise against, as they are outdated, ugly and bad for separation of concerns) then you could access the forms collection of the window:

<select id="ddlTime" onchange="forms[0].submit()">
</select>

The above is obviously assuming that the form you want to submit is the first one in the DOM.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339