I'm currently trying to make sure that the number entered in the text box is divisible by 1.25 or 1.5. The way I determine the weather is a number equal to 1.25 or 1.5, depending on what is in the other drop-down list. For example: if the selected DDL index is 1, I mod is 1.5, if it is 2 I mod is 1.25.
However, I need to show the user the cause of the error. The custom validator error message should be something like "The number must be decrypted by 1.25" or vice versa.
From what I can say, the code should work. But this is not so. I read on another forum that takes the source and makes innerText the error message should do the trick. But I have to do something wrong. When I go through my javascript function, it goes fine. Just an error message. Here is my code:
<asp:CustomValidator ID="ValidateFinHeight" runat="server" CssClass="NormLabel"
Display="Dynamic"
ControlToValidate="txtFinHeight"
ClientValidationFunction="validateFinHeight"></asp:CustomValidator>
<script type="text/javascript" language="javascript" >
function validateFinHeight(source, arguments)
{
var ddl = document.getElementById('cboTubeDia');
var ddlSelIndex = ddl.selectedIndex
switch(ddlSelIndex)
{
case 0:
arguments.isValid = true;
return;
case 1:
if(arguments.value%1.25 != 0)
{
source.innerText = "Height must be divisibly by 1.25";
arguments.isValid = false;
return;
}
else
{
arguments.isValid = true;
return;
}
case 2:
if(arguments.value%1.5 != 0)
{
source.innerText = "Height must be divisibly by 1.5";
arguments.isValid = false;
return;
}
else
{
arguments.isValid = true;
return;
}
}
}
</script>
source
share