Hello,
I have a form with several fields.
Each field can be modified:
- individually (one submit button next to the field)
- globally (a submit button at the end of the form).
Before submitting the form, a validation needs to be performed.... so I added: onSubmit="return isValid()".
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>
=====================================
I have a form with several fields.
Each field can be modified:
- individually (one submit button next to the field)
- globally (a submit button at the end of the form).
Before submitting the form, a validation needs to be performed.... so I added: onSubmit="return isValid()".
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>
=====================================