Hello

I have an HTML form in a Velocity portlet using panes. I would like to know if it is possible to validate this form with Javascript. I tried to create hidden fields but when I have more than one fields to validate, it does not work.

Here is my code :

For this code, I tried to validate "Description" and "Due date" fields.

Thank you in advance

Jean-Bruno Giard

<html>
<head>
<script language=JavaScript>
<!--
function ValidateTemplate()
{
        var FieldList = "";
        // Field1 validation.
        if (document.form.description.value == "")
        {
                FieldList = "Description\n"; // Message to user.
        };
        // Field2 validation.
        if (document.form.duedate.value == "")
        {
                FieldList = FieldList + "Due date\n"; // Message to user.
        };

// Other validations go here. Copy from above.
// Submit form or display message.
        if (FieldList == "")
        {
                document.form.submit();
        } else
        {
                alert("Please fill in the following field(s):\n\n" + FieldList);
        };
}

function save()
        {
                document.form.eventSubmit_doSave.value="Save";
                if (ValidateTemplate())
                {
                        document.form.submit();
                }
        }

//-->
</script>
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
<tr>
<td>
<form action="$jslink.Template" method="post" name="form">
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
<th>


<!-- HERE IS MY SAVE BUTTONS AND HIDDEN BUTTON -->

<input type="hidden" name="eventSubmit_doSave">
<input type="button" name="eventSubmit_doSave" value="Save" onClick="save()">
<input type="submit" name="eventSubmit_doCancel" value="Cancel">
</th>
</tr>
</table>
</td>
</tr>
<tr>
<td>


<!-- HERE IS MY HIDDEN FIELDS TO VALIDATE -->

<input type="hidden" name="description" value="$!curTemplate.getDescription()">
<input type="hidden" name="duedate" value="$!curTemplate.getDueDateText()">



<!-- HERE IS MY PANES -->

<table width="100%" border="0" cellspacing="3" cellpadding="0" style="border-bottom: groove">
<tr>
#set ( $tabNames = ["description", "context","due_date"] )
#set ( $tabActions = ["doDescription", "doContext", "doDue_date"] )
#set ( $index = 0 )
#foreach ( $name in $tabNames )
#if ( $curTab == $name )


<!-- HERE IS MY FORM -->

<td style="text-align: center">
<a href="$jslink.Template?eventSubmit_$tabActions.get($index)" target="_self" style="color: #000000">$name</a>
</td>
#else
<td class="TitleStyleClass" style="text-align: center">
<a href="$jslink.Template?eventSubmit_$tabActions.get($index)" target="_self" style="color: #FFFFFF">$name</a>
#end
</td>
#set ( $index = $index + 1 )
#end
</table>
</td>
</tr>
<tr>
<td>
<table border="1" cellpadding="3" cellspacing="0" width="100%">
#if ( $curTab == "description")
<tr>
<td width="30%" valign="top">
<b>Description : <b></td>
<td valign="top" width="70%">
<textarea wrap="hard" name="description" rows="7">$!curTemplate.getDescription()</textarea>
</td>
</tr>
#elseif ( $curTab == "context" )
<tr>
<td width="30%" valign="top">
<b>Context :<b></td>
<td valign="top" width="70%">
<textarea wrap="hard" name="context" rows="7">$!curTemplate.getContext()</textarea>
</td>
</tr>
</tr>
#elseif ( $curTab == "due_date" )
<tr>
<td width="30%" valign="middle">
<b>Due date :</b></td>
<td valign="middle" width="70%">
<input type="text" name="duedate" value="$!curTemplate.getDueDateText()" style="width: 100%">
</td>
</tr>
#end
</form>
</td>
</tr>
</table>
</body>
</html>


_________________________________________________________________
MSN Search, le moteur de recherche qui pense comme vous ! http://fr.ca.search.msn.com/



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to