RSS

Validation of control with JavaScript in popup window

17 May

Validation of control with JavaScript in popup window

Css

.input{

width:320px; margin:0 0 6px 0;

}

.label1{

display:block; float:left; width:160px; text-align:right; margin:0; padding:3px 10px 0 0;

}

JavaScript Function (Client Side)

<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>

Form (Client Side)

<form id=”info” runat=”server”>

<br />

<asp:Panel ID=”pnlInfo” runat=”server” Visible=”true”>

<label>

Name: *</label>

<input name=”Name” type=”text” value=”” style=”width: 190px” />

<br />

<label>

Email: *</label>

<input type=”text” name=”Email” style=”width: 190px” />

<br />

<label>

Daytime 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>

Street Address: *

</label>

<input type=”text” name=”Street_Address” style=”width: 190px” />

<br />

<label>

City:*

</label>

<input name=”City” type=”text” value=”” style=”width: 190px” />

<br />

<label>

State:*

</label>

<select name=”ddlState” style=”width: 100px”>

<option value=”AL”>AL</option>

<option value=”AK”>AK </option>

<option value=”AR”>AR </option>

<option value=”AZ”>AZ </option>

<option value=”CA”>CA </option>

<option value=”CO”>CO </option>

<option value=”CT”>CT </option>

<option value=”DC”>DC </option>

<option value=”DE”>DE </option>

<option value=”FL”>FL </option>

<option value=”GA”>GA </option>

<option value=”HI”>HI </option>

<option value=”ID”>ID </option>

<option value=”IA”>IA </option>

<option value=”IL”>IL </option>

<option value=”IN”>IN </option>

<option value=”KS”>KS </option>

<option value=”KY”>KY </option>

<option value=”LA”>LA </option>

<option value=”MA”>MA </option>

<option value=”MD”>MD </option>

<option value=”ME”>ME </option>

<option value=”MI”>MI </option>

<option value=”MO”>MO </option>

<option value=”MN”>MN </option>

<option value=”MS”>MT </option>

<option value=”MT”></option>

<option value=”NC”>NC </option>

<option value=”ND”>ND </option>

<option value=”NE”>NE </option>

<option value=”NH”>NH </option>

<option value=”NJ”>NJ </option>

<option value=”NM”>NM </option>

<option value=”NY”>NY </option>

<option value=”NV”>NV </option>

<option value=”OH”>OH </option>

<option value=”OK”>OK </option>

<option value=”OR”>OR </option>

<option value=”PA”>PA </option>

<option value=”RI”>RI </option>

<option value=”SC”>SC </option>

<option value=”SD”>SD </option>

<option value=”TN”>TN </option>

<option value=”TX”>TX </option>

<option value=”UT”>UT </option>

<option value=”VA”>VA </option>

<option value=”VT”>VT </option>

<option value=”WA”>WA </option>

<option value=”WI”>WI </option>

<option value=”WV”>WV </option>

<option value=”WY”>WY </option>

</select>

<br />

<label>

Zip:*

</label>

<input name=”Zip” type=”text” value=”” style=”width: 190px” />

<br />

<label style=”text-align: right”>

How did you hear about us?:</label>

<input name=”HHAU” type=”text” value=”” style=”width: 190px” />

<br />

<br />

<label>

Message:

</label>

<textarea id=”txtAdtRmrks” name=”txtAdtRmrks” rows=”7″ cols=”30″></textarea>

<div style=”text-align: center”>

<br />

<input name=”Submit” type=”submit” id=”btnSubmit” runat=”server” onclick=”MM_validateForm(‘Name’,”,’R’,’Email’,”,’RisEmail’,’Day_Phone_1_1′,”,’RisNum’,’Day_Phone_1_2′,”,’NisNum’,’Day_Phone_1_3′,”,’RisNum’,’Evening_Phone_1_1′,”,’NisNum’,’Evening_Phone_1_2′,”,’NisNum’,’Evening_Phone_1_3′,”,’NisNum’,’Street_Address’,”,’R’,’City’,”,’R’,’Zip’,”,’R’);return document.MM_returnValue”

value=”Submit” />

<input id=”Reset1″ type=”reset” value=”Reset” />

</div>

<br />

<br />

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

</asp:Panel>

</form>

Server Side or Code Behind

The value of this field code behind

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Advertisements
 
Leave a comment

Posted by on May 17, 2011 in Java Script, Vb.Net

 

Tags: ,

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: