0

I'm sending information through 2 different Submit buttons, that calls the same function but I need to know from which submit button came the call.

I have a form with 'x' parameters that I'm going to send to a js function thats going to validate the data. After I validate the data I need to send that data to diferent js function depending on the submit button press

my form is like this:

<form name="Datos_ConfiguracionRangos_Tension_Laboral" action="#" onsubmit="Consultar_ConfiguracionRangos('Tension', 'Laboral'); return false" method="post">
    <button id="button" type="submit" name="graficar" value ="graficar">Graficar</button>   
    <button id="button2" type="submit" name="guardar" value ="guardar"> Guardar Configuraciones</button>    
</form>`
BenMorel
  • 34,448
  • 50
  • 182
  • 322
rrey
  • 135
  • 1
  • 1
  • 5
  • Maybe it's worth you read the accepted answer to thi http://stackoverflow.com/questions/6348494/addeventlistener-vs-onclick – mitomed Aug 09 '13 at 20:22

1 Answers1

0

One way would be to allow your script to submit the form, and use regular buttons.

<button id="button" onclick="validateMe(this)" value ="graficar">Graficar</button> 

...then in your function:

function validateMe(e) {
     alert(e.value) <-- this tells you which button was presssed.
     .... your validation code ...
     document.forms.Datos_ConfiguracionRangos_Tension_Laboral.submit();
}
Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176
  • thanks!! that work. Basically knowing which button was pressed I can modified to do what I need to do – rrey Aug 09 '13 at 20:33