2

I have one asp.net form.
In it i have many fields which are required.
I want to display validation summary of all fields at the end of the form.
I have already checked for valid values of input controls.
Now i only want is Summary.

Here is my code for valid data input

<script language="javascript" type="text/javascript">
        function userCheck(uName) {
            var uName = document.getElementById(uName);
            var letters = /^[A-Za-z0-9]+$/;
            if (uName.value.match(letters) && uName.value.length != 0) {
                uName.style.border = "2px solid #008A2E";
                return true;
            }
            else {
                uName.value = uName.value.replace(/[\W]/g, '');
                uName.style.border = "2px solid #ff0000";
                uName.focus();
                return false;
            }
        }
</script>

This is just one function for username check.
I have many more to deal with.
Is there any way to display summary from all fields at the last when submit button is pressed ?
below solution is not working.

 function ddlcheck(ddlclg) {
            var clg = document.getElementById(ddlclg.id);
            var clgname = document.getElementById('<%= LblCollegeName.ClientID %>');
            clgname.style.display = "block";
            clgname.innerHTML = "Selected College : " + clg.options[clg.selectedIndex].value;
            clg.style.border = "1px solid #008A2E";
            if (clg.options[clg.selectedIndex].value == "Select") {
                clgname.style.display = "none";
                clg.style.border = "1px solid #ff0000";
                validationhtml = validationhtml + "<b>*</b> College" + "</br>";
            }
        }

above code is for dropdownlist.

 function select() {
            var count = 0;
            var chkSelectAll = document.getElementById('<%= ChkSelectAll.ClientID %>');
            var chkList = document.getElementById('<%= chk.ClientID %>').getElementsByTagName("input");
            for (var i = 0; i < chkList.length; i++) {
                if (chkList[i].checked == true) {
                    count++;
                }
            }
            if (count == chkList.length)
                chkSelectAll.checked = true;
            else {
                chkSelectAll.checked = false;
            }
        }

above code is for selected check boxes.

0

1 Answer 1

1

create a div ( errorreport) at required location validation summary give it style as you needed

After that

<script language="javascript" type="text/javascript">
    var validationhtml="";
    function userCheck(uName) {
        var uName = document.getElementById(uName);
        var letters = /^[A-Za-z0-9]+$/;
        if (uName.value.match(letters) && uName.value.length != 0) {
            uName.style.border = "2px solid #008A2E";
            return true;
        } else {
            uName.value = uName.value.replace(/[\W]/g, '');
            uName.style.border = "2px solid #ff0000";
            uName.focus();
            validationhtml=validationhtml +"uname is not correct" ;
            return false;
        }
    }

    function validationsummary() {

        // if using jquery
        $(".errorreport").html(validationhtml); 

        //for javascript
        document.getelementbyid("errorreport").innerHTML = validationhtml; 

        if(validationhtml == "") {
            return true;
        } else {
            return false;
        }
    }
</script>

and call validationsummary() on submit button click

Sign up to request clarification or add additional context in comments.

6 Comments

I have many more fields. Have i to call all the methods like this ?
Can you please tell me what is $(...) i have no idea about that. I need it in Javascript.
$(".errorreport") give you div with id errorreport you can write it in javascript document.getelementbyid("errorreport").innerHTML = validationhtml;
and will it properly write in that div ? i want like bullet list
ok its also easy write validationhtml=validationhtml +"uname is not correct" line as validationhtml=validationhtml +"<b>*</b> uname is not correct" +"</br>"
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.