6.15 Exercises on the Paraliel Project 221 taiExercises on the Parallel Project
ID: 3605084 • Letter: 6
Question
6.15 Exercises on the Paraliel Project 221 taiExercises on the Parallel Project main goal of th A an alidate, using regular expressions, the data input by a user before sending al of this chapter was to show how JavaScript can be used on the elient Tne side to data to a server In of Dt he tion of the last chapter you developed two forms, one for choosing prod- ices that your company offers, and one for getting feedback on customer that data to sstisfaction cts or i.Now you need to make those forms as secure as you can by checking as the input as you can to make sure it is nothing other than what you expect of arace e So, complete the followving exercises e a JavaScript script that validates all user entries for which it makes sense do so in the form that permits your customers to choose a product or service. Be sure to inform the user if any data entry is invalid. Once all input has been validated, display to your customer some relevant output related to the data that has been entered. A typical display would be a summary of the items ordered, the numbers of each item, the cost of each item and the total cost. 2. Write a JavaScript script that validates all user entries for which it makes sense to do so in the form that permits your customers to give you feedback on their experience with your business. Report to the user if a particular entry is invalid, and be sure to tell the user that everything is OK if that is the case. Some of your data validation and computation can be modeled on what you see in the text examples, but of course some will be peculiar to your particular business as well. 6.16 What Else You May Want or Need to Know 1. The official name of JavaScript is ECMASeript, although almost no one actually uses that name. See the References for further information. 2. When you view JavaScript code that is embedded in an XHTML document, especially code that you find out there on the Internet, you may see that code enclosed in a comment block. We could have done this with our embedded code shown in Figure 6.1, and if we had it would have looked like this:Explanation / Answer
Here is the different version of your problem with more input field and list.
<html>
<head>
<script type="text/javascript">
function validate()
{
var Firstname = document.getElementById('<%=txtFirstName.ClientID %>').value;
var LastName = document.getElementById('<%=txtLastName.ClientID %>').value;
var Email = document.getElementById('<%=txtEmail.ClientID %>').value;
var Pin = document.getElementById('<%=txtPin.ClientID %>').value;
var WebUrl = document.getElementById('<%=txtURL.ClientID %>').value;
var City = document.getElementById('<%=DropDownList1.ClientID %>').value;
if (Firstname == "")
{
alert("Enter First Name");
return false;
}
if (LastName == "") {
alert("Enter Last Name");
return false;
}
if (Email == "") {
alert("Enter Email");
return false;
}
var emailPat = /^(".*"|[A-Za-z]w*)@([d{1,3}(.d{1,3}){3}]|[A-Za-z]w*(.[A-Za-z]w*)+)$/
var EmailmatchArray = Email.match(emailPat);
if (EmailmatchArray == null) {
alert("Your email address seems incorrect. Please try again.");
return false;
}
if (City == "Select") {
alert("Select City");
return false;
}
}
</script>
</head>
<body>
<table class="style1">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="First Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="Last Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="Label3" runat="server" Text="Email"></asp:Label>
</td>
<td class="style2">
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label4" runat="server" Text="Pin"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtPin" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label5" runat="server" Text="URL"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtURL" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label6" runat="server" Text="City"></asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" Height="20px" Width="135px">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Select</asp:ListItem>
<asp:ListItem>Chandigarh</asp:ListItem>
<asp:ListItem>Delhi</asp:ListItem>
<asp:ListItem>Mumbai</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Submit"
OnClientClick="return validate();" />
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
</table>
</body>
<html>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.