www.webdeveloper.com
Results 1 to 10 of 10

Thread: Help me with my form

  1. #1
    Join Date
    Nov 2010
    Posts
    10

    Help me with my form

    hi,i would like to make a simple hotel.Firstly,I created a simple form(with no validations etc) but i don't know how when i press Submit button then this details to save in a database using Mysql. Can anyone tell me how to do this this?
    Code:
    <%--
        Document   : StartPage
        Created on : 14-Nov-2010, 16:07:29
        Author     : theo
    --%>
    
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <script>
        function onClick()
          {
          return true;
          }
      </script>
      <html>
    
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
            <h1>Hotel Details</h1>
             <form name="form1" action="Details.jsp" method="post" onsubmit="javascript:return onClick()" >
              Rooms
              <br>
             <select id="Origin" name="Origin" onchange = "originChanged()">
    
      <option>Please Choose</option>
      <option>Bed and Breakfast</option>
      <option>Room</option>
        </select>
              </br>
    
              <h2></h2>
             Number of people
             <br>
        <select id="Origin" name="Origin">
        <option>Please Choose</option>
        <option>1</option>
        <option>2</option>
        <option>3</option>
        <option>4</option>
        </select>
             </br>
              <h3></h3>
             Number of rooms
        <br>
             <select id="Origin" name="Origin">
      <option>Please Choose</option>
      <option>1</option>
      <option>2</option>
      <option>3</option>
      <option>4</option>
       </select>
        </br>
         <h4></h4>
             Type of room
    <br>
             <select id="Origin" name="Origin" onchange = "originChanged()">
    
      <option>Please Choose</option>
      <option>Single</option>
      <option>Double</option>
      <option>Luxury double</option>
      </select>
            </br>
     <h5></h5>
             Breakfast
     <br>
    <select id="Origin" name="Origin">
      <option>Please Choose</option>
      <option>Yes</option>
      <option>No</option>
       </select>
     </br>
     <br>
     <h5></h5>
             Start Date
        <select id="Origin" name="Origin">
        <option>Please Choose</option>
        <option>1</option>
        </select>
        <select id="Origin" name="Origin">
        <option>Please Choose</option>
        <option>December 2010</option>
        <option>January 2011</option>
        <option>February 2010</option>
        <option>March 2010</option>
        <option>April 2010</option>
        <option>May 2010</option>
        </select>
      </br>
       <h5></h5>
             Until
        <select id="Origin" name="Origin">
        <option>Please Choose</option>
        <option>1</option>
        </select>
        <select id="Origin" name="Origin">
        <option>Please Choose</option>
        <option>December 2010</option>
        <option>January 2011</option>
        <option>February 2010</option>
        <option>March 2010</option>
        <option>April 2010</option>
        <option>May 2010</option>
        </select>
      </br>
    	</p>
    	<p><input id=submit1 type=submit value=Submit name=submit1>
    	</p>
      <form name="form1" action="PageTwo.jsp" method="post">
    
    
    
    
    
             </form>
        </body>
    </html>

  2. #2
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582

    Cool

    Please ignore what I just posted about this. I am supposed to be in the JavaScript forum, not Java. Don't know how I ended up, here. Sorry.
    ^_^

  3. #3
    Join Date
    Nov 2010
    Posts
    10
    i posted my question in a wrong field???because as i see my question has moved!!!!

  4. #4
    Join Date
    Jan 2009
    Posts
    3,346
    What do you have in place for your form processing jsp page? I also notice you have 2 form elements but the one at the far bottom is empty. Was that intended?

  5. #5
    Join Date
    Nov 2010
    Posts
    10
    criterion 9 sorry about my code was very bad and i had many errors which i corrected!!!
    I would like to ask you something if anybody knows.
    I would like to do this.

    A hotel should have some single and some double rooms. Each category of room will have a price per person per night, excluding breakfast. If a single person books a double room a single-occupancy supplement should be charged. For example
    Double room with shower and WC:
    If 2 people sharing, price per person per night, &#163;60.
    If 1 person only - &#163;90 per night.
    There should be 3 or 4 different types of room. You could have, for example, single and double rooms with a shower, double rooms with a bath, and a luxury double room. Each category should have a different price.

    I have written this code

    Code:
              <h2></h2>
             Number of people
             <br>
        <select id="People" name="People" onchange = "peopleChanged()">
        <option>Please Choose</option>
        <option value="1" >1</option>
        <option value="2" >2</option>
        <option value="3" >3</option>
        <option value="4" >4</option>
        </select>
             </br>
              <h3></h3>
             Number of rooms
        <br>
             <select id="Rooms" name="Rooms">
      <option>Please Choose</option>
      <option value="1" >1</option>
      <option value="2" >2</option>
      <option value="3" >3</option>
      <option value="4" >4</option>
       </select>
        </br>
         <h4></h4>
             Type of room
    <br>
             <select id="Type" name="Type">
    
      <option>Please Choose</option>
      <option>Single</option>
      <option>Double</option>
      <option>Luxury double</option>
      </select>
            </br>
    I do not know what can i do with the prices!!!!i must create a drop down list with the prices and then with a validation method to do the 'if'???

  6. #6
    Join Date
    Jan 2009
    Posts
    3,346
    Maybe try writing out very basically what you want to happen. In this case you have something like:
    Code:
    Grab the price for the selected room type
    if multiple occupancy
    ....add surcharge
    continue with remaining script
    Does that make it a little clearer for you?

  7. #7
    Join Date
    Nov 2010
    Posts
    10
    hmmmm!!!!if i try to do a database with this fields for example:
    type of room price
    single 60
    double 70
    etc

    it will be a good idea?

  8. #8
    Join Date
    Jan 2009
    Posts
    3,346
    Maybe add an extra column with the amount to add for each additional occupant? That seems like it would fit your scenario to me.

  9. #9
    Join Date
    Nov 2010
    Posts
    10
    I will try to make more clear my scenario.
    I have created the next jsp form with Netbeans.

    Code:
    <&#37;--
        Document   : StartPage
        Created on : 14-Nov-2010, 16:07:29
        Author     : theo
    --%>
    
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    
    
    
    
    
    <script language="javascript">
        function onClick()
          {
          return true;
          }
    
    
       function DayChanged()
        {
        var idx1 = document.form1.StartMonth.selectedIndex;
        var idx3 = document.form1.StartDate.selectedIndex;
        var idx2 = document.form1.FinishMonth.selectedIndex;
        var idx4 = document.form1.FinishDate.selectedIndex;
        if (idx3 > idx4)
       	 {
         document.form1.FinishDate.selectedIndex = idx3;
         }
        var now = new Date();
        var idx5 = now.getDate() -1;
        return MonthChanged();
        }
    
        function MonthChanged()
          {
              var idx1 = document.form1.StartMonth.selectedIndex;
       var idx2 = document.form1.FinishMonth.selectedIndex;
    
       if (idx1 > idx2)
       	 {
         document.form1.FinishMonth.selectedIndex = idx1;
         return DayChanged();
         }
    
          }
    
        function checkToDate()
        {
        var idx1 = document.form1.StartMonth.selectedIndex;
        var idx2 = document.form1.StartDay.selectedIndex;
        var idx3 = document.form1.FinishMonth.selectedIndex;
        var idx4 = document.form1.FinishDay.selectedIndex;
        }
    
      </script>
      <html>
    
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
    
        <body>
            <h1>Hotel Details</h1>
    
            <form name="form1" action="NameDetails.jsp" method="post" onsubmit="return onClick()">          
             Number of people
    
             <br>
    
             <select id="People" name="People" onchange = "PeopleChanged()">
        <option>Please Choose</option>
        <option value="1" >1</option>
        <option value="2" >2</option>
        <option value="3" >3</option>
        <option value="4" >4</option>
        </select>
    
             </br>
              <h2></h2>
             Number of rooms
        <br>
    
        <select id="Rooms" name="Rooms">
      <option>Please Choose</option>
      <option value="1" >1</option>
      <option value="2" >2</option>
      <option value="3" >3</option>
      <option value="4" >4</option>
       </select>
        </br>
    
        <h3></h3>
             Type of room
    <br>
             <select id="Type" name="Type">
    
      <option>Please Choose</option>
      <option>Single - 50&#163;</option>
      <option>Double - 60&#163;</option>
      <option>Luxury double - 70&#163;</option>
      </select>
            </br>
     <h5></h5>
             Breakfast
     <br>
    <select id="Breakfast" name="Breakfast">
      <option>Please Choose</option>
      <option>Yes(+10&#163;)</option>
      <option>No</option>
       </select>
     </br>
     <br>
    
     <h5></h5>
             Start Date
    
      <select id="StartDate" name="StartDate" onchange ="DayChanged()">
    
          <%
    
          for (int i=1;i<=31;i++) {
    
          %>
    
          <option value="<%=i%>"><%=i%></option>
    
          <%
    
          }
    
          %>
        <select id="StartMonth" name="StartMonth" onchange="MonthChanged()">
        <option>December 2010</option>
        <option>January 2011</option>
        <option>February 2011</option>
        <option>March 2011</option>
        <option>April 2011</option>
        <option>May 2011</option>
        </select>
      </br>
    
      <br>
       <h6></h6>
             Until
    
    
    
          <select id="FinishDate" name="FinishDate" onchange = "checkToDate()">
    
          <%
    
          for (int i=1;i<=31;i++) {
    
          %>
    
          <option value="<%=i%>"><%=i%></option>
    
          <%
    
          }
    
          %>
    
          </select>
        <select id="FinishMonth" name="FinishMonth" onchange = "checkToDate()">
        <option>December 2010</option>
        <option>January 2011</option>
        <option>February 2011</option>
        <option>March 2011</option>
        <option>April 2011</option>
        <option>May 2011</option>
        </select>
      </br>
    	</p>
    
            <br>
            <input class="submit" type="submit"
    	value="Submit" />
            </br>
            </form>
    
      </body>
    </html>
    First of all i would like when i chose for example
    number of rooms:2
    type of room:double - 60&#163;
    breakfast: yes(+10&#163

    then somewhere to sum up the cost.In this case 120+20(breakfast)=140&#163;

    other example
    number of rooms:3
    type of room:double - 60&#163;
    breakfast: no

    then somewhere to sum up the cost.In this case 180+0(breakfast)=180&#163;

    This is the first step.
    The second step when i press the submit button then these details i want them to save in a mysql database. Any ideas?

  10. #10
    Join Date
    Jan 2009
    Posts
    3,346
    I'm not sure what you are asking for...do you have a specific problem with syntax or something?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles