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

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -