PDA

View Full Version : Validation not working


sri
05-02-2003, 09:24 PM
I am trying to validate field but i could not .
My validation is when I go from one field to other it should validate the next two fields . my code is below , Any one can help me please . When the status field is Active (A) the effdate and termdate should be disabled ,For inactive status it shold be activated .

<td valign=top>
<select ID="SelectStatus" onblur="validateStatus(this)" size="1" >
<OPTION Value="A" <%If oRS.Fields("File_Status") = "A" Then Response.Write "Selected"%>>Active</OPTION>
<OPTION Value="N" <%If oRS.Fields("File_Status") = "N" Then Response.Write "Selected"%>>Inactive</OPTION>
</SELECT>
</td>

my validation is this

function validateStatus() {
if (pField.value == "A") {
EffButton.disabled = true;
TermButton.disabled = true;
EffDate.disabled = true;
TermDate.disabled = true;
}
else {
EffButton.disabled = false;
TermButton.disabled = false;
EffDate.disabled = false;
TermDate.disabled = false;
}
}



when I try to validate ,I am getting remote script error ,page involed does not support remote scripting .

Mr J
05-04-2003, 10:49 PM
Not too sure about this but I think you should be including the form name and field name in the argument

document.formname.fieldname.disabled=true

HairyTeeth
05-05-2003, 12:12 AM
The remote scripting error is related to the ASP code you are using. Is the page an ASP page (ie. mypage.asp)?

As for the validation, see if this helps. Note that ive used buttons and text fields - i have no idea what type of iinputs the non-button fields are so I just used text.

<html>
<head>
<title>Demo</title>
<script type="text/javascript" language="javascript">
<!--;

function validateStatus(fld) {
var selectedOption = fld.options[fld.selectedIndex].value;
var EffButton = document.theForm.EffButton;
var TermButton = document.theForm.TermButton;
var EffDate = document.theForm.EffDate;
var TermDate = document.theForm.TermDate;

if(selectedOption !="defaultSelected"){
if (selectedOption == "A") {
EffButton.disabled = true;
TermButton.disabled = true;
EffDate.disabled = true;
TermDate.disabled = true;
}else {
EffButton.disabled = false;
TermButton.disabled = false;
EffDate.disabled = false;
TermDate.disabled = false;
}

}
}
//-->
</script>

</head>

<body>

<form name="theForm">
<select name="SelectStatus" onchange="validateStatus(this)" size="1" >
<option value="defaultSelected" selected="selected">Choose...</option>
<OPTION Value="A">Active</OPTION>
<OPTION Value="N">Inactive</OPTION>
</SELECT>
<br />
<input type="button" name="EffButton" value="EffButton" />
<input type="text" name="EffDate" value="" />EffDate
<br />
<input type="button" name="TermButton" value="TermButton" />
<input type="text" name="TermDate" value="" />TermDate
</form>
</body>
</html>

Note that ive used an onchange event handler to call the function.