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>`
4

1 回答 1

0

一种方法是允许您的脚本提交表单,并使用常规按钮。

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

...然后在您的功能中:

function validateMe(e) {
     alert(e.value) <-- this tells you which button was presssed.
     .... your validation code ...
     document.forms.Datos_ConfiguracionRangos_Tension_Laboral.submit();
}
于 2013-08-09T20:10:36.740 回答