RSS

html validation with popup

22 Mar

 <script language=”JavaScript” type=”text/JavaScript”>
<!–
        function MM_findObj(n, d) { //v4.01
            //n=”ctl00_ContentPlaceHolder1_” + n;
            var p, i, x; if (!d) d = document; if ((p = n.indexOf(“?”)) > 0 && parent.frames.length) {
                d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
            }
            if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
            for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
            if (!x && d.getElementById) x = d.getElementById(n); return x;
        }

        function MM_validateForm() { //v4.0
            var i, p, q, nm, test, num, min, max, errors = ”, args = MM_validateForm.arguments;
            for (i = 0; i < (args.length – 2); i += 3) {
                test = args[i + 2]; val = MM_findObj(args[i]);
                if (val) {
                    nm = val.name; ; if ((val = val.value) != “”) {
                        if (test.indexOf(‘isEmail’) != -1) {
                            p = val.indexOf(‘@’);
                            if (p < 1 || p == (val.length – 1)) errors += ‘- ‘ + nm + ‘ must contain an e-mail address.\n’;
                        } else if (test != ‘R’) {
                            num = parseFloat(val);
                            if (isNaN(val)) errors += ‘- ‘ + nm + ‘ must contain a number.\n’;
                            if (test.indexOf(‘inRange’) != -1) {
                                p = test.indexOf(‘:’);
                                min = test.substring(8, p); max = test.substring(p + 1);
                                if (num < min || max < num) errors += ‘- ‘ + nm + ‘ must contain a number between ‘ + min + ‘ and ‘ + max + ‘.\n’;
                            }
                        }
                    } else if (test.charAt(0) == ‘R’) errors += ‘- ‘ + nm + ‘ is required.\n’;
                }
            } if (errors) alert(‘The following error(s) occurred:\n’ + errors);
            document.MM_returnValue = (errors == ”);
        }
        //–>
        function ShowTextFocus(obj, size, ids) {
            if (obj.value.length == size) {
                document.getElementById(ids).focus();
            }
        }
    </script>

html code

 

 <h1>
        Contact Us</h1>
    <form id=”form1″ runat=”server”>
    <label>
        First Name: *</label>
    <input name=”Member_Name” type=”text” value=”” />
    <br />
    <label>
        Last Name: *</label>
    <input name=”Last_Name” type=”text” value=”” />
    <br />
    <label>
        Account Number: *</label>
    <input type=”text” name=”Account_Number” />
    <br />
    <label>
        Email Address: *</label>
    <input type=”text” name=”Email” />
    <br />
    <label>
        Day Time Phone: *</label>
    <input type=”text” name=”Day_Phone_1_1″ id=”Day_Phone_1_1″ size=”3″ maxlength=”3″
        onkeyup=”ShowTextFocus(this,3,’Day_Phone_1_2′);” style=”width: 50px” />
    –
    <input type=”text” name=”Day_Phone_1_2″ id=”Day_Phone_1_2″ size=”3″ maxlength=”3″
        onkeyup=”ShowTextFocus(this,3,’Day_Phone_1_3′);” style=”width: 50px” />
    –
    <input type=”text” name=”Day_Phone_1_3″ id=”Day_Phone_1_3″ size=”4″ maxlength=”4″
        onkeyup=”ShowTextFocus(this,4,’Evening_Phone_1_1′);” style=”width: 50px” />
    <br />
    <label>
        Evening Phone:
    </label>
    <input type=”text” name=”Evening_Phone_1_1″ id=”Evening_Phone_1_1″ size=”3″ maxlength=”3″
        onkeyup=”ShowTextFocus(this,3,’Evening_Phone_1_2′);” style=”width: 50px” />
    –
    <input type=”text” name=”Evening_Phone_1_2″ id=”Evening_Phone_1_2″ size=”3″ maxlength=”3″
        onkeyup=”ShowTextFocus(this,3,’Evening_Phone_1_3′);” style=”width: 50px” />
    –
    <input type=”text” name=”Evening_Phone_1_3″ id=”Evening_Phone_1_3″ size=”4″ maxlength=”4″
        style=”width: 50px” />
    <br />
    <label>
        Best time to call:
    </label>
    <input type=”text” name=”Call_Time” />
    <br />
    <label>
        What is your question in regards to?</label><br />
    <select name=”Question”>
        <option>Member Services</option>
        <option>Loans</option>
        <option>Mortgages</option>
        <option>Driver’s Choice</option>
        <option>Human Resources</option>
        <option>Business Services</option>
    </select>
    <%–<br />
              <label>Question / Comments:</label>
              <br />
              <textarea name=”Comments” cols=”50″></textarea>–%>
    <br />
    <label>
        Additional Remarks:</label>
    <textarea id=”txtAdtRmrks” name=”txtAdtRmrks” rows=”7″ cols=”55″></textarea>
    <br />
    <br />
    <div style=”text-align: center”>
        <asp:Button ID=”btnSubmit” runat=”server” Text=”submit” OnClientClick=”MM_validateForm(‘Member_Name’,”,’R’,’Last_Name’,”,’R’,’Account_Number ‘,”,’R’,’Email’,”,’RisEmail’,’Day_Phone_1_1′,”,’RisNum’,’Day_Phone_1_2′,”,’RisNum’,’Day_Phone_1_3′,”,’RisNum’,’Evening_Phone_1_1′,”,’NisNum’,’Evening_Phone_1_2′,”,’NisNum’,’Evening_Phone_1_3′,”,’NisNum’);return document.MM_returnValue” />
        <input id=”Reset1″ type=”reset” value=”Reset” />
    </div>
    </form>
    <br />
    <br />

 

Access these control value to code behind(vb.net)

Import namespaces

 


Imports System.Net
Imports System.Net.Mail
Imports System.Configuration.ConfigurationManager

 

 Dim strMemberName As String = HttpUtility.HtmlEncode(Trim(Request.Form(“Member_Name”)))
            Dim strlName As String = HttpUtility.HtmlEncode(Trim(Request.Form(“Last_Name”)))
            Dim strMemberNumber As String = HttpUtility.HtmlEncode(Trim(Request.Form(“Account_Number”)))
            Dim strEmail As String = HttpUtility.HtmlEncode(Trim(Request.Form(“Email”)))

            Dim strDayPhoneNo1_1 As String = HttpUtility.HtmlEncode(Trim(Request.Form(“Day_Phone_1_1”)))
            Dim strDayPhoneNo1_2 As String = HttpUtility.HtmlEncode(Trim(Request.Form(“Day_Phone_1_2”)))
            Dim strDayPhoneNo1_3 As String = HttpUtility.HtmlEncode(Trim(Request.Form(“Day_Phone_1_3”)))

            Dim strEveningPhoneNo1_1 As String = HttpUtility.HtmlEncode(Trim(Request.Form(“Evening_Phone_1_1”)))
            Dim strEveningPhoneNo1_2 As String = HttpUtility.HtmlEncode(Trim(Request.Form(“Evening_Phone_1_2”)))
            Dim strEveningPhoneNo1_3 As String = HttpUtility.HtmlEncode(Trim(Request.Form(“Evening_Phone_1_3”)))

            Dim strCallTime As String = HttpUtility.HtmlEncode(Trim(Request.Form(“Call_Time”)))

            Dim strQuestion As String = HttpUtility.HtmlEncode(Trim(Request.Form(“Question”)))

            ‘Dim strComments As String = HttpUtility.HtmlEncode(Trim(Request.Form(“Comments”)))

            Dim txtAdtRmrks As String = HttpUtility.HtmlEncode(Trim(Request.Form(“txtAdtRmrks”)))


    <strong>* </strong>Fields are required.
 

Advertisements
 
Leave a comment

Posted by on March 22, 2011 in ASP.Net Validation

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: