Bonjour,
J'ai un fichier .jsp que contient un formulaire de plusieurs champs.
Chaque entrée peut être:
- modifiée individuellement (1 Submit à coté du champ)
- modifée globalement (1 submit a la fin du formulaire)

Avant de soumettre un formulaire, il faut exécuter un validation (function validate()) ====> Pour cette raison, j'ai ajouté dans la définition du formulaire: onSubmit="return validate()"

Chaque bouton "submit" est activé par onClick="reDirect(0,<paramName, paramIndex)".
Cette fonction (0 => individuel, 1 => global) permet tout simplement de construire l'appel de modif.jsp avec le nom du paramètre en paramètre.

Le probleme c'est que MEME SI LA VALIDATION NE PASSE PAS, le fichier modif.jsp est appelé!!!
C'est comme si le "onClick" primait sur "onSubmit" puisque peut importe le résultat de la function validate, la fonction reDirect est excecutée!


Je ne sais plus que faire..... HELP!!!!

========================
<html>
<title>Example</title>
<head>
<script language=JavaScript>

var fieldIndex;
var modifType;

function validate()
{
var str = document.attributes.elements[fieldIndex].value;
alert("str="+str);
if (str.match(/^(\s)*$/) )
{
alert("Ne peut être vide!");
document.attributes.elements[fieldIndex].select();
document.attributes.elements[fieldIndex].focus();
return false;
}
return true;
}

function reDirect(target, fieldName,index)
{
fieldIndex=index;
modifType=target;

if (target == 0) document.attributes.action="modif_param.jsp?paramName="+fieldName;

if(target == 1) document.attributes.action="modif_all_params.jsp";
document.attributes.submit();
}
</script>
</head>
<%@page language="java" %>
<body>
<form onSubmit="return validate()" method="post" name="attributes" action="">
<table>
<tbody>
<%
int fieldInd=0;
for (int i=0; i<5; i++)
{
String paramValue = "A"+String.valueOf(i);
String paramName = "Name"+String.valueOf(i);
%>
<tr>
<td>
<input type=text name=<%=paramName%> value=<%=paramValue%>>
<input type="image" onClick="reDirect(0,'<%=paramName%>',<%=String.valueOf(fieldInd)%>)" src="../images/M.gif">
</td>
</tr>
<%
fieldInd++;
}
%>
</tbody>
</table>
<input onclick=reDirect(1,'','','') type=button value="Modificar todos">
</form>
</body>
</html>


If the validation does not pass, the form needs to be shown with the data previously entered by the user.

Now, I haven't even come to the previous problem I have mentioned..... my problem is that if a field is empty, the function isValid() recognize it (message sent) .... but the reDirect function is performed!!!!

Could you help please?


I am using a javascript function "reDirect" to perform the multiple submit button:

- target = 0 => Individual submit
= 1 => Global submit
- fieldName => Fieldname to be modified
- index => Field number of fieldName.

I have two global variables: fieldIndex and modifType, so the validation function will know whith variable to look at (with fieldIndex) and the modifType ( 0=> individual, 1 => global)

The scriptlet is :
==================================
<html>
<title>Test</title>
<head>
<script language=JavaScript>
<!--- oculta el script para navegadores antiguos

var fieldIndex;
var modifType;

function isValid()
{
var str = document.attributes.elements[fieldIndex].value;
if (str.match(/^(\s)*$/) )
{
alert("This field ield cannot be empty");
document.attributes.elements[fieldIndex].select();
document.attributes.elements[fieldIndex].focus();
return false;
}
}

function reDirect(target, fieldName,index)
{
fieldIndex=index;
modifType=target;

if(target == 0) document.attributes.action="modif_one.jsp?name=fieldName";
if(target == 1) document.attributes.action="modif_all.jsp";
document.attributes.submit();
}

// end hiding from old browsers -->
</script>
</head>
<%@page language="java" %>
<body>
<form onSubmit="return isValid()" method="post" name="attributes" action="">
<table>
<tbody>
<%
int fieldInd=0;
for (int i=0; i<5; i++)
{
String paramValue = "A"+String.valueOf(i);
String paramName = "Name"+String.valueOf(i);
%>
<tr>
<td>
<input type=text name=<%=paramName%> value=<%=paramValue%>>
<input type="image" onClick="reDirect(0,'<%=paramName%>',<%=String.valueOf(fie
ldInd)%>)" src="../images/M.gif">
</td>
</tr>
<%
fieldInd++;
}
%>
</tbody>
</table>
<input onclick=reDirect(1,'','','') type=button value="Modify all">
</form>
</body>
</html>
=====================================