473,804 Members | 2,292 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dropdown calculates date

7 New Member
Can someone guide me in the right direction? I have a drop down with values of 1 through 14 (1 = 1 day, 2 = 2 days, 3 = 3 days, ect). The onchange the drop down should calculate the days starting from today. If today is 4/1/08 and the user selects 3 then the output should show 4/4/08. However, my problem is that the date is not changing.

[HTML]<select name="lstPrpTyp eDesc" id="lstPrpTypeD esc" onblur="validat e(this.value, this.id)" onchange="????" >[/HTML]

[PHP]<?php
$PostOptions = array("0" => "[Select]",
"1" => "3",
"2" => "4",
"3" => "5",
"4" => "6",
"5" => "7",
"6" => "14");

$current = time();
$postdays=$_SES SION['values']['lstPost'];
$exp_date = time() + (86400 * $postdays);
$expdate = date('l, m-d-Y H:i:s A', $exp_date);
echo $expdate;?>[/PHP]
Expand|Select|Wrap|Line Numbers
  1. function ajaxtime(val) {var req;try{req = new XMLHttpRequest();} catch (e){try{req = new ActiveXObject("Msxml2.XMLHTTP");} catch (e) {try{req = new ActiveXObject("Microsoft.XMLHTTP");} catch (e){alert("Please Update Your Browser");return false;}}}req.onreadystatechange = function(){if(req.readyState == 4){document.getElementById('response').innerHTML = req.responseText;}}req.open("GET", "time.php", true);req.send(null);}
Apr 1 '08 #1
12 1605
JazzSingerNL
4 New Member
Some small changes made, both to script and PHP file.
This works for me (IE and FF):

PHP:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $postdays = $_REQUEST['lstPost'];
  3. $exp_date = time() + (86400 * $postdays);
  4. $expdate = date('l, m-d-Y H:i:s A', $exp_date);
  5. echo $expdate;
  6. ?>
  7.  
HTML / JS:

Expand|Select|Wrap|Line Numbers
  1. <select name="lstPrpTypeDesc" id="lstPrpTypeDesc" onchange="ajaxtime(this.value)">
  2.   <option value="3">3</option>
  3.   <option value="4">4</option>
  4.   <option value="5">5</option>
  5.   <option value="6">6</option>
  6.   <option value="7">7</option>
  7.   <option value="14">14</option>
  8. </select>
  9.  
  10. <div id="response">&nbsp;</div>
  11.  
  12. <script type="text/javascript" language="JavaScript">
  13.  
  14.   function ajaxtime(val) {
  15.       var req;
  16.       try{
  17.         req = new XMLHttpRequest();
  18.       } catch (e) {
  19.         try {
  20.           req = new ActiveXObject("Msxml2.XMLHTTP");
  21.         } catch (e) {
  22.           try{
  23.             req = new ActiveXObject("Microsoft.XMLHTTP");
  24.           } catch (e) {
  25.             alert("Please Update Your Browser");
  26.             return false;
  27.           }
  28.         }
  29.       }
  30.       req.onreadystatechange =  function() {
  31.                                   if(req.readyState == 4){
  32.                                     document.getElementById('response').innerHTML = req.responseText;
  33.                                   }
  34.                                 }
  35.       req.open("POST", "time.php?lstPost="+val, true);
  36.       req.send(null);
  37.     }
  38.  
  39. </script>
  40.  
Apr 2 '08 #2
watdaduck
7 New Member
Thanks JazzSingerNL I will give that a shot
Apr 3 '08 #3
watdaduck
7 New Member
JazzSingerNL it woks like a charm. However, I have 1 more question. How would I store the value of div id="response" into a database?
Apr 3 '08 #4
acoder
16,027 Recognized Expert Moderator MVP
Make it into a form field and submit the form to a server-side script which saves the data to the database. Alternatively, use a hidden field.

You could also do this via Ajax or even when making the original date request (if appropriate).
Apr 4 '08 #5
watdaduck
7 New Member
Make it into a form field and submit the form to a server-side script which saves the data to the database. Alternatively, use a hidden field.

You could also do this via Ajax or even when making the original date request (if appropriate).
Acoder - I'm not sure what you mean.
Apr 4 '08 #6
acoder
16,027 Recognized Expert Moderator MVP
Which part do you not understand?

With your current code, an easy solution would be to set a hidden field to the value of the response, so that it can be submitted.
Apr 4 '08 #7
watdaduck
7 New Member
Sorry I don't get it?

[HTML]input name="txtExp" id="txtExp" value="<div id="response"> </div>"[/HTML]
Apr 4 '08 #8
watdaduck
7 New Member
I have the following code but it seems the hidden field is always 1 step behind. How do I go about getting the current value?

[HTML]<div id="response">< input type="hidden" name="txtExp" value="<?php echo $_SESSION['txtExp']; ?>"/></div>[/HTML]
Apr 5 '08 #9
acoder
16,027 Recognized Expert Moderator MVP
Sorry I don't get it?

[HTML]input name="txtExp" id="txtExp" value="<div id="response"> </div>"[/HTML]
No, the value should be equal to the content of the div, e.g. its innerHTML, not the div itself.
Apr 5 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1994
by: CSharpguy | last post by:
I'm trying to populate a drop down with dates from a data field in my data base but I want the format like MM/dd/yyyy instead of 1/1/2006 12:00 PM How can I my date to show as 1/1/2006? I'm populating the dropdown via a dataset and doing a: string time = Convert.ToDateTime(dataset.tables.rows.toString()).ToShortDateString(); dropdown.datatexfield = time; dropdown.datavaluefield = time dropdown.databind();
2
3074
by: trint | last post by:
In my winform, I have 3 dropdown style comboboxes. I want the program to always start with the "Todays date" to be selected in the three comboboxes. example of todays date selected by using all three combo dropdown boxes: cboDropDownStyle1 = June | cboDropDownStyle2 = 26 | cboDropDownStyle3 = 2007 Those items already exist in the comboboxes, I just want them
4
3433
by: Panna | last post by:
Hey there I am using phpMyAdmin and MySQL to develop a dbase application. I have a dropdown menu on one of the pages which gets populated automatically with data from a table in the database. The code for this is as follows: $sql3="SELECT ID, UploadDate FROM Telkom"; $result2=mysql_query($sql3); $options="";
3
1852
by: natalievl | last post by:
Hi, I have a Drop Down List that is being populated by a sql server database with the following query... sqlSchedule = ("SELECT cast(DATE_FROM as smalldatetime) AS DATE from EVENTS WHERE ITEMID = '" + txtid + "'"); The DropDown is populated with '30/09/2007 12:00:00 AM' Can someone please tell me how to change the date format in the dropdown to 30/09/2007.
7
2303
by: tabm2004 | last post by:
I have an ASP main page with date fields dropdown like From date Date .. Month .....Year To date Date.. Month..... Year whenever i open mainpage.asp in the browser, i am needed to select the To & From dates. Instead of that i want the system date should be generated automatically in the dropdown boxes. Plz advice the code for this.
4
4593
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet reservation of available resources (laptops, beamers, etc). The MySql database queries are already in place, as is the ASP administration panel. The frontend that users will see however, still needs some work. I'm really close, but since I'm no...
5
10366
by: =?Utf-8?B?Y2hlY2tyYWlzZXJAY29tbXVuaXR5Lm5vc3BhbQ== | last post by:
I have a VS 2008 ASP.NET webform that has a reportview tag on it, accessing an .RLDC report in local report. The columns for the report are essentially: Month Item #1 Item#2 Item#3 I would like to add a checkbox or dropdown control to the .RLDC and have Item #1, Item #2, or Item #3 display conditionally based on a checkbox being clicked or a dropdown value being selected.
7
2293
by: microsoftboy | last post by:
Hi, Using the following selection criteria, I am able to list the data from mysql db, but I would like to provide the following options for users: Select All Data, Select None. I am not sure if this is possiible. Any help would be greatly appreciated. Here's my code <h4>SEARCH</h4> <form action="<?php echo $_SERVER ?>" method = "post" target = "right">
0
9711
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9591
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10331
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10087
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9166
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7631
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4306
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.