Author Topic: how to assign textbox value as variables in same page?  (Read 1581 times)

0 Members and 1 Guest are viewing this topic.

Offline pollysalTopic starter

  • Irregular
  • Posts: 24
    • View Profile
how to assign textbox value as variables in same page?
« on: March 18, 2010, 10:40:03 AM »
may i know if in php i can assign the textbox value from the user input as variables and then display the result of in the same page.

assume, user insert the checkin and checkout date, then it wil automatically show the numbers of the day the user will stay at the hotel.

any suggestion will really appreciates because i have no ideas what should i do ...

below is the code 

Code: [Select]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" media="all" href="calendar-win2k-1.css" title="win2k-cold-1" />
<script type="text/javascript" src="Kalendar/calendar.js"></script>
<script type="text/javascript" src="Kalendar/calendar-en.js"></script>
<script type="text/javascript" src="Kalendar/calendar-setup.js"></script>
<script type="text/javascript" src="Kalendar/ew.js"></script>
<script type="text/javascript"></script>
<title>SistemAPOS</title>
<style type="text/css">
<!--
.style7 {color: #FFFFFF}
.style8 {
color: #000000;
font-weight: bold;
}
.style10 {color: #FFFFFF; font-weight: bold; }
.style11 {font-weight: bold}
-->
</style>

</head>

<body>

<form action="findroom.php" method="post">

  <p>Check Room Availbility</p>
  <p>Date In
    <label>
      <input type="text" name="datein" id="datein" />
      <input name="datein" type="image" id="dateA" src="Kalendar/ew_calendar.gif" width="16" height="15" border="0" />
  <script type="text/javascript">
</script>
            </strong>
  <script type="text/javascript">Calendar.setup(
{
inputField : "datein", // ID of the input field
ifFormat : "%Y-%m-%d", // the date format
button : "dateA" // ID of the button
}
);
document.write(ifFormat);
</script>
    </label>
  </p>
  <p>Date Out
    <input type="text" name="dateout2" id="dateout" />
    <input name="dateout" type="image" id="dateB" src="Kalendar/ew_calendar.gif" width="16" height="15" border="0" />
    </strong>
    <script type="text/javascript">Calendar.setup(
{
inputField : "dateout", // ID of the input field
ifFormat : "%Y-%m-%d", // the date format
button : "dateB" // ID of the button
}
);
document.write(ifFormat);
</script>
  </p>
  <p>Number of Days : Supposely this is the place where it will display how many days the user will stay</p>
  <p>
    <label>
      <input type="submit" name="Check" id="Check" value="Submit" />
    </label>
  </p>
</form>
</body>
</html>



Offline Psycho

  • Guru
  • Freak!
  • *
  • Posts: 7,751
    • View Profile
Re: how to assign textbox value as variables in same page?
« Reply #1 on: March 18, 2010, 10:46:16 AM »
Form values can only be accessed by the PHP processor when the values are submitted. For example, by clicking a submit button and submitting the form - which would refresh the page. To submit the values without refreshing the page you will need to use AJAX. In this case use JavaScript to submit the values and receive the results.

There are plenty of AJAX tutorials to get you started.
The quality of the responses received is directly proportional to the quality of the question asked.

I do not always test the code I provide, so there may be some syntax errors. In 99% of all cases I found the solution to your problem here: http://www.php.net

Offline scvinodkumar

  • Enthusiast
  • Posts: 209
  • Gender: Male
  • PHP Web Developer
    • View Profile
    • Web Collection
Re: how to assign textbox value as variables in same page?
« Reply #2 on: March 18, 2010, 10:51:15 AM »
I dont know whether i understand your question correctly,

let me clear first, You want to show the number of days(stay at the hotel) between checkin and checkout date, right?

if so, then you can use javascript to find the difference between these two dates before submitting the form
« Last Edit: March 18, 2010, 10:52:20 AM by scvinodkumar »

Offline Psycho

  • Guru
  • Freak!
  • *
  • Posts: 7,751
    • View Profile
Re: how to assign textbox value as variables in same page?
« Reply #3 on: March 18, 2010, 11:23:40 AM »
I dont know whether i understand your question correctly,

let me clear first, You want to show the number of days(stay at the hotel) between checkin and checkout date, right?

if so, then you can use javascript to find the difference between these two dates before submitting the form

I think I may have misrread that. I thought there was some need for PHP processing (e.g. see if days were available). Yes, if you only need to calculate the days, then you would only need to use JavaScript.
The quality of the responses received is directly proportional to the quality of the question asked.

I do not always test the code I provide, so there may be some syntax errors. In 99% of all cases I found the solution to your problem here: http://www.php.net

Offline pollysalTopic starter

  • Irregular
  • Posts: 24
    • View Profile
Re: how to assign textbox value as variables in same page?
« Reply #4 on: March 20, 2010, 06:19:06 PM »
yeah..i finally realized that i don't need to use php since it's just need to run on the client side to get the days between two days.
he..he..i'm still green in this web development, so i don't understand many stuff..
i'll look forward to learn ajax and javascript to implement what i wanted to do..
thanks for those who reply and provide me with the keyword that i needed.. :)