Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > บทความจากสมาชิก > List วันเกิด Mktime แสดงข้อมูลวันที่ตามวันที่จริง


 

List วันเกิด Mktime แสดงข้อมูลวันที่ตามวันที่จริง

วันนี้มาดูการสร้างlist วันเกิด กำหนดวัน/เดือน/ปี ตามความเป็นจริงแบบง่ายๆกันครับ เช่น ปีนี้เดือนกุมภาพันธ์ มี 28 วัน ก็แสดง 28วัน และปีไหนมี 29 วันก็แสดง29วัน ตามปีนั้นๆ

Code (PHP)
01.<?php
02.$monthOptions = '';
03.$dayOptions = '';
04.$yearOptions = '';
05. 
06.for($month=1; $month<=12; $month++)
07.{
08.    $monthName = date("M", mktime(0, 0, 0, $month));
09.    $monthOptions .= "<option value=\"{$month}\">{$monthName}</option>\n"
10.}
11.for($day=1; $day<=31; $day++)
12.{
13.    $dayOptions .= "<option value=\"{$day}\">{$day}</option>\n";
14.}
15.for($year=2011; $year>=1950; $year--)
16.{
17.    $yearOptions .= "<option value=\"{$year}\">{$year}</option>\n";
18.}
19.?>
20.<html>
21.<head>
22.<script type="text/javascript">
23.function updateDays()
24.{
25.    //Create variables needed   
26.    var monthSel = document.getElementById('month');   
27.    var daySel   = document.getElementById('day');   
28.    var yearSel  = document.getElementById('year');   
29.    var monthVal = monthSel.value;   
30.    var yearVal  = yearSel.value;
31.     
32.    //Determine the number of days in the month/year   
33.    var daysInMonth = 31;   
34.    if (monthVal==2)   
35.    {
36.    daysInMonth = (yearVal%4==0 && (yearVal%100!=0 || yearVal%400==0)) ? 29 : 28;   
37.    }
38.    else if (monthVal==4 || monthVal==6 || monthVal==9 || monthVal==11)   
39.    {
40.        daysInMonth = 30;   
41.    }
42.     
43.    //Add/remove options from days select list as needed   
44.    if(daySel.options.length > daysInMonth)
45.    {   //Remove excess days, if needed       
46.        daySel.options.length = daysInMonth;   
47.    }
48.    while (daySel.options.length != daysInMonth)
49.    {   //Add additional days, if needed       
50.        daySel.options[daySel.length] = new Option(daySel.length+1, daySel.length+1, false);   
51.    }
52.     
53.    return;
54.}
55.     
56.</script>
57.</head>
58.</html>


   
Hate it
Don't like it
It's ok
Like it
Love it
Total Votes: 221Overall Rating: 4.9 / 5
Share
Bookmark.   

  By : ATVa
  Article : บทความเป็นการเขียนโดยสมาชิก หากมีปัญหาเรื่องลิขสิทธิ์ กรุณาแจ้งให้ทาง webmaster ทราบด้วยครับ
  Score Rating :
  Create Date : 2011-07-08
  Download : No files
Sponsored Links
ThaiCreate.Com Forum
Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   





ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่