Click here to Skip to main content
15,889,659 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a small project that is to practice how to integrate JavaScript code into an
ASP.NET web application to perform client-side processing and validation. Develop
a simple one-page web application that allows the user to fill airline reservation
details.
The webpage must provide the following functionality using JavaScript:
o Provide a dropdown with the options One-way, Round-trip, Multi-city.
If the user selects One-way option, provide the following controls:
o text box to enter FROM city
o text box to enter TO city, verify that the FROM and TO cities are different
o text box to enter DEPARTURE DATE, verify that the departure date is after today
If the user selects Round-trip option, provide the following controls:
o text box to enter FROM city
o text box to enter TO city, verify that the FROM and TO cities are different
o text box to enter DEPARTURE DATE, verify that the departure date is
after today
o text box to enter RETURN DATE, verify that the return date is after
departure date
If the user selects the Multi-city option, provide the following controls:
o text box to enter FROM city of the first flight
o text box to enter TO city of the first flight, verify that the FROM and TO
cities of first flight are different
o text box to enter DEPARTURE DATE of the first flight, verify that the
departure date is after today
o text box to enter FROM city of the second flight, and automatically fill it with
TO city of the first flight
o text box to enter TO city of second flight, verify that FROM and TO cities
of second flight are different
o text box to enter DEPARTURE DATE of the second flight, verify that the departure date of the second flight is after the first flight
o Provide a button called Add Another Flight, clicking on which automatically shows new text boxes to enter FROM, TO and DEPARTURE DATE of the flight

What I have tried:

This is my code so far:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="Assignment05.Home" %>





    <title>
     

function onFlightChange() {

	var flight = document.getElementById("ddFlights").value;
	var oneWay = document.getElementById("oneWay");
	var roundTrip = document.getElementById("roundTrip");
	var multiCity = document.getElementById("multiCities");

	if (flight == 1) {
		oneWay.style.display = "block";
		roundTrip.style.display = "none";
		multiCity.style.display = "none";
	}
	else if (flight == 2) {
		roundTrip.style.display = "block";
		oneWay.style.display = "none";
		multiCity.style.display = "none";
	}
	else if (flight == 3) {
		multiCity.style.display = "block";
		roundTrip.style.display = "none";
		oneWay.style.display = "none";
	}
	
}


function addTextBox() {
	var div = document.createElement('DIV');
	div.innerHTML = GetDynamicTextBox("");
	document.getElementById("TextBoxContainer").appendChild(div);

}

     <script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
        	<asp:DropDownList ID="ddFlights" runat="server" onchange="onFlightChange()">
				<asp:ListItem Value="0" Text="Please Select Your Flight"></asp:ListItem>
				<asp:ListItem Value="1" Text="One-Way"></asp:ListItem>
				<asp:ListItem Value="2" Text="Round-Trip"></asp:ListItem>
				<asp:ListItem Value="3" Text="Multi-cities"></asp:ListItem>
			</asp:DropDownList>
			<br />
			<br />
			<table style="display:none;" id="oneWay">
				<tr>					<td>						<asp:Label ID="Label1" runat="server" Text="From"></asp:Label>
					</td>					<td>						<asp:TextBox ID="TextBox1" runat="server" Text=""></asp:TextBox>
					</td>				</tr>				<tr>					<td>						<asp:Label ID="Label2" runat="server" Text="To"></asp:Label>
					</td>					<td>					<asp:TextBox ID="TextBox2" runat="server" Text=""></asp:TextBox>
					</td>				</tr>				<tr>					<td>						<asp:Label ID="Label3" runat="server" Text="Depart Date"></asp:Label>
					</td>					<td>						<asp:TextBox ID="TextBox3" runat="server" Text=""></asp:TextBox>
					</td>				</tr>			</table>
			<table id="roundTrip" style="display:none;">
				<tr>					<td>						<asp:Label ID="Label4" runat="server" Text="From"></asp:Label>
					</td>					<td>						<asp:TextBox ID="TextBox4" runat="server" Text=""></asp:TextBox>
					</td>				</tr>				<tr>					<td>						<asp:Label ID="Label5" runat="server" Text="To"></asp:Label>
					</td>					<td>						<asp:TextBox ID="TextBox5" runat="server" Text=""></asp:TextBox>
					</td>				</tr>				<tr>					<td>						<asp:Label ID="Label6" runat="server" Text="Depart Date"></asp:Label>
					</td>					<td>						<asp:TextBox ID="TextBox6" runat="server" Text=""></asp:TextBox>
					</td>				</tr>				<tr>					<td>						<asp:Label ID="Label7" runat="server" Text="Return Date"></asp:Label>
					</td>					<td>						<asp:TextBox ID="TextBox7" runat="server" Text=""></asp:TextBox>
					</td>				</tr>				</table>

			<table id="multiCities" style="display:none;">
				<tr>					<td>						<asp:Label ID="Label8" runat="server" Text="From"></asp:Label>
					</td>					<td>						<asp:TextBox ID="TextBox8" runat="server" Text=""></asp:TextBox>
					</td>				</tr>				<tr>					<td>						<asp:Label ID="Label9" runat="server" Text="To"></asp:Label>
					</td>					<td>						<asp:TextBox ID="TextBox9" runat="server" Text=""></asp:TextBox>
					</td>				</tr>				<tr>					<td>						<asp:Label ID="Label10" runat="server" Text="Depart Date"></asp:Label>
					</td>					<td>						<asp:TextBox ID="TextBox10" runat="server" Text=""></asp:TextBox>
					</td>				</tr>				<tr>					<td>						<asp:Label ID="Label11" runat="server" Text="Return Date"></asp:Label>
					</td>					<td>						<asp:TextBox ID="TextBox11" runat="server" Text=""></asp:TextBox>
					</td>				
				</tr>				<tr>					<td><asp:Button ID="Button2" runat="server" Text="Add Another Flight" onclick="AddTextBox()"/></td>				</tr>			</table>
        </div>
    	<asp:Button ID="Button1" runat="server" Text="Display" />
    </form>
	
</body>
</html>
I am stuck in creating another flight function and how to verify the date required in text boxes. Please Help Me !!!
Posted
Updated 1-May-19 22:26pm
Comments
Richard MacCutchan 2-May-19 3:30am    
And what is the question?
Member 14186004 2-May-19 3:56am    
I am stuck in adding another flight and verify the required text boxes. How can I add more text boxes to enter FROM, TO and DEPARTURE DATE of the third flight?

1 solution

You can easily add text boxes. But what you can't do, is have them exist so they have viewstate. You can't access the values easily on the back end.

ASP.NET is over a decade obsolete, why aren't you using MVC at least?

I think the question is that you use javascript to do validation, not create the controls
 
Share this answer
 
Comments
Member 14186004 2-May-19 4:31am    
This is just my assignment in school. How can I make validations based on the requirements?
Christian Graus 2-May-19 4:35am    
Are you allowed to use jQuery? Get an event on the drop box selection changing, read it, and I'd create a placeholder for each group of controls, so you can show and hide them in groups.
Member 14186004 2-May-19 4:39am    
No, we are learning the basic. Therefore we cannot use jQuery :(
Christian Graus 2-May-19 4:47am    
That's a shame. You will learn verbose methods you will never use again. But then, no one uses ASP.NET, so nothing you're learning is terribly useful, I'm sorry

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900