I have looked into the older post http://quomon.com/ViewQuestion.aspx?questionId=4229&
I tried to apply the same script and it worked partially,
The problem is I want to enable/diable only few fields in my form. The problem I am having is that when I select No, all the fields are getting disabled. I tried tweaking this code a bit, but i coudlnt succeed. Is there any way i can do this?
Thanks
function Form1_Validator(theForm)
{
var alertsay = ""; // define for long lines
// alertsay is not necessary for your code,
// but I need to break my lines in multiple lines
// so the code won't extend off the edge of the page
// check if no drop down has been selected
if (theForm.Dept.selectedIndex < 0)
{
alert("Please select one of the \"Department\" options.");
theForm.Dept.focus();
return (false);
}
// check if the first drop down is selected, if so, invalid selection
if (theForm.Dept.selectedIndex == 0)
{
alert("The first \"Department\" option is not a valid selection.");
theForm.Dept.focus();
return (false);
}
// check to see if the field is blank
if (theForm.NH.value == "")
{
alert("You must eter an NH.");
theForm.NH.focus();
return (false);
}
// require at least 3 characters be entered
if (theForm.NH.value.length < 3)
{
alert("Please enter at least 3 characters in the \"NH\" field.");
theForm.NH.focus();
return (false);
}
// allow ONLY alphanumeric keys, no symbols or punctuation
// this can be altered for any "checkOK" string you desire
var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var checkStr = theForm.NH.value;
var allValid = true;
for (i = 0; i < checkStr.length; i++)
{
ch = checkStr.charAt(i);
for (j = 0; j < checkOK.length; j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}
if (!allValid)
{
alert("Please enter only letter and numeric characters in the \"NH\" field.");
theForm.NH.focus();
return (false);
}
alertsay = "All Validations have succeeded. "
alertsay = alertsay + "This is just a test page. There is no submission page."
alert(alertsay);
return (false);
// replace the above with return(true); if you have a valid form to submit to
}
<script type="text/javascript">
function disable_controls( state) {
var frm = document.forms[0] ;
var len = frm.elements.length ;
var cnt = 0 ;
for ( var i=0; i < len; i++) {
var elem = frm.elements[i] ;
if (elem.type != "hidden") {
if (elem.type != "radio") {
elem.disabled = state ;
}
}
}
}
Required |
| SubmitANewTicket |
| ContactInformation |
| UserName |
|
| EMail |
|
| Location |
|
| Phone: |
|
|
ProblemClassification |
| Department: |
Select a Department
T2
T16
|
|
NH:
|
*
|
|
SSN
|
*
|
|
IsRepresentativePayeeInvolved
*
|
|
Yes
No
|
|
| Attachments |
|
| Representaivepayeeinvolved |
| Reppayee |
* |
| ZipCode |
* |
| orgainizationname |
*
|