Monday 18 January 2016

JS/Jade: how to update a page based on a dropdown?

Note up front that I am just learning JS and this might be better in the JS subreddit, but I think there's a node/Jade-specific aspect so I thought I would start here. But there might be an obvious answer that I just don't know the terminology well enough to Google for.I have a page that looks like the following:form#formSetup (name="league_details",method="post",action="/addleaguedetails") select(name='league_select') each league in leagues option(value=league.id) #{league.name} option(value="-1") New input#inputName(type="text", placeholder="name", name="name", required="true") What I would like would be to have the input prefill with the name of the league that has been selected. One idea I had is that instead of passing in an array of leagues, I could pass in a map of index to league and use that index for the option value instead of the league id, so that i could more easily reference the selected league based on the selected option value, but I'm not sure if that's the best way or really how to make the input fields update when the select happens. Do I use a JS function or is there something Jade-specific for this?

Submitted January 18, 2016 at 07:26PM by mwilykat

No comments:

Post a Comment