ASP.NET - Jquery validation in external js file for aspx file

Asked By anbu n on 21-May-13 05:14 AM
<script type="text/javascript" src="script/JQuery.js"></script>
 
    <script type="text/javascript">
    $(function(){
    $('#<%=btnedit.ClientID %>').click(function(){
 
    var Isvalid=true;
    var filter = /^[1-9][0-9]*$/
    if($('#<%= tbxarea.ClientID %>').val()=='')
    {
        $('#<%= tbxarea.ClientID %>').css({"border-color": "red",
             "border-width":"1px",
             "border-style":"solid"});
        Isvalid=false;
    }
    else
    {
        if(filter.test($('#<%= tbxarea.ClientID %>').val()))
        {
            $('#<%= tbxarea.ClientID %>').css({"border-color": "",
             "border-width":"",
             "border-style":""});
        }
        else
        {
            $('#<%= tbxarea.ClientID %>').css({"border-color": "red",
             "border-width":"1px",
             "border-style":"solid"});
            Isvalid=false;
        }
    }
 
    if($('#<%= tbxmatte.ClientID %>').val()=='')
    {
        $('#<%= tbxmatte.ClientID %>').css({"border-color": "red",
             "border-width":"1px",
             "border-style":"solid"});
        Isvalid=false;
    }
    else
    {
        if(filter.test($('#<%= tbxmatte.ClientID %>').val()))
        {
            $('#<%= tbxmatte.ClientID %>').css({"border-color": "",
             "border-width":"",
             "border-style":""});
        }
        else
        {
            $('#<%= tbxmatte.ClientID %>').css({"border-color": "red",
             "border-width":"1px",
             "border-style":"solid"});
            Isvalid=false;
        }
    }
    if($('#<%= tbxglossy.ClientID %>').val()=='')
    {
        $('#<%= tbxglossy.ClientID %>').css({"border-color": "red",
             "border-width":"1px",
             "border-style":"solid"});
        Isvalid=false;
    }
    else
    {
        if(filter.test($('#<%= tbxglossy.ClientID %>').val()))
        {
            $('#<%= tbxglossy.ClientID %>').css({"border-color": "",
             "border-width":"",
             "border-style":""});
        }
        else
        {
            $('#<%= tbxglossy.ClientID %>').css({"border-color": "red",
             "border-width":"1px",
             "border-style":"solid"});
            Isvalid=false;
        }
    }
    if($('#<%= tbxtextured.ClientID %>').val()=='')
    {
        $('#<%= tbxtextured.ClientID %>').css({"border-color": "red",
             "border-width":"1px",
             "border-style":"solid"});
        Isvalid=false;
    }
    else
    {
        if(filter.test($('#<%= tbxtextured.ClientID %>').val()))
        {
            $('#<%= tbxtextured.ClientID %>').css({"border-color": "",
             "border-width":"",
             "border-style":""});
        }
        else
        {
            $('#<%= tbxtextured.ClientID %>').css({"border-color": "red",
             "border-width":"1px",
             "border-style":"solid"});
            Isvalid=false;
        }
    }
    return Isvalid;
    });
 
    });
    </script>
 
---------------------------------------------------
 
Above is a jQuery function written in aspx page , how to implement the same in external js file
Robbe Morris replied to anbu n on 21-May-13 10:28 PM
Why would you not put the contents of your script in an external file and include a reference to it just like you did the script/jQuery.js file?
anbu n replied to Robbe Morris on 22-May-13 01:18 AM
Thanks for your reply

can u please send a sample code for my understanding
Harish Mady replied to anbu n on 23-May-13 10:28 AM
Pass a control id as a parameter to the function which is placed in external js file.
Then by replacing the id with the control id's which u want u can obtain that id.
something like 
var buttonID = document.getElementbyID(sender.id.replace("ControlID","ButtonID"));