html - Send in form if button pressed -
i have 2 buttons in form (that js listening can show fields in form).
<div class="btn-group" role="group" aria-label="..."> <button type="button" class="btn btn-default" name="distance" id="one_way_button">distance & time</button> <button type="button" class="btn btn-default" name="distance" id="stored_button">stored address</button> </div>
i send button pressed in form post data. using ruby on rails, if matters. not sure need change html send button pressed.
you can store button name in hidden input before submit
function fnsubmitform(obj) { document.getelementbyid("buttonname").value = obj.value document.getelementbyid("myform").submit(); }
onclick call above function
<div class="btn-group" role="group" aria-label="..."> <input type="hidden" id="buttonname" name="buttonname" value="" /> <input type="button" class="btn btn-default" name="distance" id="one_way_button" onclick="fnsubmitform(this)" value="distance & time" /> <input type="button" class="btn btn-default" name="distance" id="stored_button" onclick="fnsubmitform(this)" value="stored address" /> </div>
Comments
Post a Comment