This is pretty basic stuff, so maybe I'm being blind to it, however I cannot get this working.
I've got a form, and part of that form has a Select item. I've stripped out the inline JS and it looks like the following:
<select class="form-control selectpicker" id="restaurantChain" name="restaurantChain" data-live-search="true">
<option value="null">Not a chain</option>
<option value="1234">12345</option>
</select>
Now, I submit this to a function which captures the data and I'm logging it out, however it's not working for the select item, everything else is fine:
var restaurantChain = req.param('restaurantChain');
I'm getting undefined
but I cannot figure out why. Here's my full code:
Form
<form method="post" action="restaurant-management/manage">
<input type="hidden" value="<%= restaurant.id %>" name="restaurantId" id="restaurantId"/>
<td><input type="text" value="<%= restaurant.name %>" name="restaurantName" id="restaurantName" class="form-control"></input></td>
<td><input type="text" value="<%= restaurant.location %>" name="restaurantLocation" id="restaurantLocation" class="form-control"></input></td>
<td>
<select class="form-control selectpicker" id="restaurantChain" name="restaurantChain" data-live-search="true">
<option value="null">Not a chain</option>
<% if(typeof chains != "undefined") { %>
<% _.each(chains, function(chain){ %>
<option value="<%= chain.id %>" <% if(restaurant.chain == chain.id) { %> selected <% } %> >
<%= chain.name %>
</option>
<% }) %>
<% } %>
</select>
</td>
<td class="text-center"><input type="submit" class='btn btn-info btn-s' name="editButton" value="Edit"> <input type="submit" class="btn btn-danger btn-s" name="deleteButton" value="Delete"></td>
</form>
Function
manageRestaurant: function(req, res) {
var restaurantName = req.param('restaurantName');
var restaurantId = req.param('restaurantId');
var restaurantLocation = req.param('restaurantLocation');
var restaurantChain = req.param('restaurantChain');
var checkboxes = req.param('checkboxes');
console.log(restaurantName); //Works fine
console.log(restaurantLocation); //Works fine
console.log(restaurantChain); //Undefined....what?!
}
Page Source
<tr>
<form method="post" action="restaurant-management/manage">
<input type="hidden" value="571c8ad57f18f8a441417a57" name="restaurantId" id="restaurantId"/>
<td><input type="text" value="Nandos" name="restaurantName" id="restaurantName" class="form-control"></input></td>
<td><input type="text" value="London - Oxford Street" name="restaurantLocation" id="restaurantLocation" class="form-control"></input></td>
<td>
<select class="form-control selectpicker" id="restaurantChain" name="restaurantChain" data-live-search="true">
<option value="123">Not a chain</option>
<option value="571a0b7e09e2eff63befa5fa" >
Nandos
</option>
<option value="571a0b8409e2eff63befa5fb" >
McDonalds
</option>
<option value="571df9378fb28b8545ce4b23" >
TGI Fridays
</option>
<option value="571dfb09f0e2af92456bc53f" >
Subway
</option>
</select>
</td>
<td class="text-center"><input type="submit" class='btn btn-info btn-s' name="editButton" value="Edit"> <input type="submit" class="btn btn-danger btn-s" name="deleteButton" value="Delete"></td>
</form>
</tr>
Answer
If you still want to use a table, rather than restyling the page with CSS to get the same result, you can submit the form data using a Javascript function. This gets the values from the elements on the page, and posts them.