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,027

HOME > PHP > PHP Forum > จะคำนวณอายุ จากช่อง textBox ของวันเดือนปีเกิด โดยอัตโนมัตทันที ทำอย่างไรคะ



 

จะคำนวณอายุ จากช่อง textBox ของวันเดือนปีเกิด โดยอัตโนมัตทันที ทำอย่างไรคะ

 



Topic : 075881

Guest




กก

ให้มันขึ้นที่คำว่า อายุ ทันที ทำอย่างไรคะ



Tag : PHP, MySQL







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-03-21 11:43:26 By : อยากจะถาม View : 8992 Reply : 8
 

 

No. 1



โพสกระทู้ ( 3,844 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์
Twitter Facebook

ลองประยุกต์ใช้งานดูน่ะครับ อันนี้พอใส่วันเดือนปีเกิด ต้องกด enter เพื่อ คำนวณน่ะครับ
ตัวอย่าง
Code (PHP)
<script>
function getAge(dateString) {
    var today = new Date();	
    var birthDate = new Date(dateString);
    var age = today.getFullYear() - birthDate.getFullYear();
    var m = today.getMonth() - birthDate.getMonth();
    if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
        age--;
    }
   if(age !="")
   {
   document.getElementById('age').value = age;
   }
}
</script>

input birthdate :<input type="text" id="birthday" value="" onkeydown="if(this.value !='' && this.value.length==10 && event.keyCode==13){getAge(this.value);}"> enter to calculate<br>
current your age :<input type="text" id="age" readonly="readonly"> years







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-03-21 12:15:13 By : mangkunzo
 


 

No. 2

Guest


ถ้าม่กด enter จะได้ไหมคะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-03-21 16:54:58 By : อยากจะถาม
 

 

No. 3



โพสกระทู้ ( 5,146 )
บทความ ( 26 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์


เคยเห็นในบอร์ดอยู่นะ เรื่องการเลือกวันที่แล้วคำนวนอายุอัตโนมัติ ลองค้นดูก่อนนะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-03-21 17:54:43 By : deawx
 


 

No. 4



โพสกระทู้ ( 3,844 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์
Twitter Facebook

ตอบความคิดเห็นที่ : 2 เขียนโดย : อยากจะถาม เมื่อวันที่ 2012-03-21 16:54:58
รายละเอียดของการตอบ ::
แล้วแต่จะประยุกต์ใช้งานครับ ลองทำต่อได้เลย

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-03-21 18:23:08 By : mangkunzo
 


 

No. 5



โพสกระทู้ ( 5,146 )
บทความ ( 26 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์


https://www.thaicreate.com/search?cx=partner-pub-0639452308651048%3Amgul3k-tjap&cof=FORID%3A10&ie=UTF-8&q=%E0%B8%AD%E0%B8%B2%E0%B8%A2%E0%B8%B8+%E0%B8%AD%E0%B8%B1%E0%B8%95%E0%B9%82%E0%B8%99%E0%B8%A1%E0%B8%B1%E0%B8%95%E0%B8%B4&s=&submit=
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-03-22 01:53:21 By : deawx
 


 

No. 6

Guest


จากกระทู้ https://www.thaicreate.com/php/forum/025618.html
โดยมีสคริปส์Code (PHP)
Code (JavaScript)
<?php
function calAge($dateofbirth)
{
	/*$d=explode("/",$dateofbirth);
	$b=mktime(0,0,0,$d[1],$d[0],$d[2]);*/
	$b=$dateofbirth;
	$p=mktime(0,0,0,date("m"),date("d"),date("Y"));
	$age = ($p-$b)/(3600*24*365.25);
	$newage=explode(".",$age);
	return $newage[0];
}
?>



วิธีนำมาประยุกต์ใช้ยังไงคะ ใ่อะไรตรงไหนคะ ขอที่กระทู้ถามคะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-03-22 09:02:12 By : อยากจะถาม
 


 

No. 7



โพสกระทู้ ( 283 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

Code (PHP)
<?php
function calAge($dateofbirth)
{
	/*$d=explode("/",$dateofbirth);
	$b=mktime(0,0,0,$d[1],$d[0],$d[2]);*/
	$b=$dateofbirth;
	$p=mktime(0,0,0,date("m"),date("d"),date("Y"));
	$age = ($p-$b)/(3600*24*365.25);
	$newage=explode(".",$age);
	return $newage[0];
}
?>




ถ้าตาม code ดังกล่าว คือส่งค่าตัวแปร $dateofbirth มาให้ฟังก์ชั่น $dateofbirth ก็คือวันเกิด

จากนั้นนำ $dateofbirth มาลบกับวันที่ปัจจุบัน หารด้วย 3600*24*365.25 (วินาที X 24ชั่วโมง x 365 วัน)

จากนั้นนำค่าผลลัพธ์ที่ได้มา explode เพื่อนำค่าอายุมาแสดงผล

ถ้าอยากให้แสดงผลใน input ก็ลบ return $newage[0]; ออก

document.getElementById("ชื่อ ID ที่ต้องการให้แสดง").value=$newage[0];
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-03-22 09:29:45 By : asustak
 


 

No. 8

Guest


มันยังไม่ออกมาคะ แถมยัง error คะ Parse error: syntax error, unexpected '=' in C:\AppServ\www\clinicsystem\pt_manag_add.php on line 63
ไม่ทราบผิดตรงไหนอะไรยังไงคะ

โค๊ดคะ
Code (PHP)
<!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>
<script language="JavaScript" type="text/javascript">
<!--
function checkform ( form )
{

 if (form.pt_id.value == "") {
    alert( "กรุณากรอกรหัส ผู้ป่วยด้วยค่ะ" );
    form.pt_id.focus();
    return false ;
  }
  if (form.pt_name.value == "") {
    alert( "กรุณากรอกชื่อผู้ป่วยด้วยค่ะ" );
    form.pt_name.focus();
    return false ;
  }

  if (form.pt_card.value == "") {
    alert( "กรุณากรอกเลขบัตรประจำตัวประชาชนด้วยค่ะ" );
    form.pt_card.focus();
    return false ;
  }

  if (form.pt_birth.value == "") {
    alert( "กรุณากรอกวัน/เดือน/ปีเกิดด้วยค่ะ" );
    form.pt_birth.focus();
    return false ;
  }

  if (form.pt_address.value == "") {
    alert( "กรุณากรอกที่อยู่ด้วยค่ะ" );
    form.pt_address.focus();
    return false ;
  }
  
  return true ;
}
//-->
//////////////////////////////////////////////////////////////////
function check_number() {
e_k=event.keyCode
//if (((e_k < 48) || (e_k > 57)) && e_k != 46 ) {
if (e_k != 13 && (e_k < 48) || (e_k > 57)) {
event.returnValue = false;
alert("ต้องเป็นตัวเลขเท่านั้น... \nกรุณาตรวจสอบข้อมูลของท่านอีกครั้ง...");
}
} 

</script>
<script>
<?php
function calAge($dateofbirth)
{
	/*$d=explode("/",$dateofbirth);
	$b=mktime(0,0,0,$d[1],$d[0],$d[2]);*/
	$b=$dateofbirth;
	$p=mktime(0,0,0,date("m"),date("d"),date("Y"));
	$age = ($p-$b)/(3600*24*365.25);
	$newage=explode(".",$age);

	document.getElementById('pt_id').value=$newage[0];
}
?></script>
<title>เพิ่มข้อมูลผู้ป่วย</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
<script language="JavaScript" src="calendar_eu.js"></script>
	<link rel="stylesheet" href="calendar.css">
<!--
.style45 {color: #000000}
.style46 {color: #FFFFFF}
body {
	background-color: #93EAFF;
}
.style5 {	font-size: 36px;
	font-family: AngsanaUPC;
	font-weight: bold;
}
.style11 {font-size: 22px; font-weight: bold;}
.style12 {font-size: 20px; font-family: AngsanaUPC;}
.style17 {font-size: 22px; font-weight: bold; color: #000000; font-family: AngsanaUPC; }
.style2 {font-family: AngsanaUPC}
.style6 {font-family: AngsanaUPC; font-weight: bold; font-size: 20px; }
-->
</style>
</style>
<style type="text/css">
<!--
.style2 {font-family: AngsanaUPC}
body {
	background-color: #93EAFF;
	background-image: url(icon1/%E0%B8%9E%E0%B8%B7%E0%B9%89%E0%B8%99%E0%B8%AB%E0%B8%A5%E0%B8%B1%E0%B8%87cartoon_computer_wallpaper_1414.jpg);
}
.style31 {font-size: 20px; color: #FFFFFF; font-family: AngsanaUPC;}
.style33 {font-family: "MS Sans Serif"}
.style34 {font-family: "MS Sans Serif"; font-weight: bold; font-size: 12px; }
.style37 {font-family: "MS Sans Serif"; font-weight: bold; font-size: 14px; }
.style38 {font-size: 14px}
.style39 {font-family: "MS Sans Serif"; font-size: 14px; }
.style40 {
	font-family: "MS Sans Serif";
	font-size: 15px;
	font-weight: bold;
}
.style43 {
	color: #FF0000;
	font-size: 10px;
}
-->
</style>
</head>

<body>
	<?php 
	include("include/config.php"); 
	   $pt_id = $_REQUEST['pt_id'];  
	   $new_id_cus = mysql_result(mysql_query("Select Max(pt_id)+1 as MaxID from  patient"),0,"MaxID");//เลือกเอาค่า id ที่มากที่สุดในฐานข้อมูลและบวก 1 เข้าไปด้วยเลย
            if($new_id_cus==''){ // ถ้าได้เป็นค่าว่าง หรือ null ก็แสดงว่ายังไม่มีข้อมูลในฐานข้อมูล
                $pt_id="00001";
            }else{
                $pt_id=sprintf("%05d",$new_id_cus);//ถ้าไม่ใช่ค่าว่าง
            }
	   
	   ?>
<form name="frmregister" action="pt_manag_addata.php" method="post" onSubmit="return checkform(this);">
<table width="955" height="796" border="1" align="center">
  <tr>
    <td height="26" colspan="2"><? require('header.php') ?></td>
  </tr>
  <tr>
  <td colspan="2" valign="top" bordercolor="#93EAFF" background="image/top.jpg" bgcolor="#93EAFF">
	   <marquee>
        <div align="center"><span class="style31">ระบบการให้บริการคลินิกหมอบุญพิมล </span></div>
      </marquee></td>
  </tr>
  <tr>
	 <td width="17" height="692" align="left" valign="top" bgcolor="#FFFFFF"><? include ('menu_user.php')?></td>
      <td width="922" valign="top" bgcolor="#FFFFFF"><br />
      <table width="590" border="0" align="center" cellspacing="3" bgcolor="#FFFFFF">
        <tr>
          <td height="13" colspan="2" background="image/top.jpg" bgcolor="#62a6d5"><div align="center" class="style40">เพิ่มข้อมูลผู้ป่วย</span></span></div></td>
          </tr>
        <tr bgcolor="#dcf9ff">
          <td height="14" bgcolor="#dcf9ff"><span class="style37">รหัสผู้ป่วย</span></td>
          <td height="14" bgcolor="#dcf9ff"><label>
<input name="pt_id1" type="text" id="pt_id1" size="3" maxlength="2" />
<input name="pt_id" type="text" style="background: #C0F9BD" id="pt_id" size="10" value="<? echo $pt_id  ?>" readonly="readonly"/>
<span class="style43 style33">*กรุณาใส่ ปีที่ที่เป็นสมาชิก เช่น ปี2555ให้ใส่แค่ 55          </span></label></td>
        </tr>
        <tr>
          <td width="173" bgcolor="#dcf9ff" class="style37">ชื่อ-นามสกุล<font color="#FF0000">**</font></td>
            <td width="377" bgcolor="#dcf9ff"><span class="style34 style33 style38">
              
              <select name="pt_zname" id="pt_zname"   class="dropdown">
                <option value="--คำนำหน้าชื่อ--">--คำนำหน้าชื่อ--</option>
                <option value="นาย">นาย</option>
                <option value="นาง">นาง</option>
                <option value="นางสาว">นางสาว</option>
                <option value="เด็กหญิง">เด็กหญิง</option>
                <option value="เด็กชาย">เด็กชาย</option>
                <option >อื่นๆ</option>
              </select>
              
              <input name="pt_name" type="text" id="pt_name" size="30" />
              </span></td>
          </tr>
        <tr>
          <td bgcolor="#dcf9ff" class="style37">เพศ</td>
            <td bgcolor="#dcf9ff"><span class="style39">
              <input name="pt_sex" type="radio" value="ชาย" checked="checked" />
              ชาย &nbsp;
              <input name="pt_sex" type="radio" value="หญิง" />
              หญิง </span></td>
          </tr>
        <tr>
          <td height="13" bgcolor="#dcf9ff"><span class="style37">เลขบัตรประจำตัวประชาชน
            <label><font color="#FF0000">**</font></label>
  </span></td>
            <td bgcolor="#dcf9ff"><span class="style34 style33 style38">
              <label>
                <input name="pt_card" type="text" id="pt_card"  onkeypress=check_number(); size="13" maxlength="13" />
                &nbsp;</label>
              </span></td>
          </tr>
        <tr>
          <td height="14" bgcolor="#dcf9ff"><span class="style37"><span class="style2 style33"><strong>วัน/เดือน/ปีเกิด
                  <label><font color="#FF0000">**</font></label>
          </strong></span></span></td>
            <td bgcolor="#dcf9ff"><span class="style39">
              <label></label>
              <span class="style34 style33 style38">
              <input name="pt_birth" type="text" id="pt_birth" />     <script language="JavaScript">
	new tcal ({
		// form name
		'formname': 'frmregister',
		// input name
		'controlname': 'pt_birth'
	});

	</script>
              </span></span></td>
          </tr>
        <tr>
          <td bgcolor="#dcf9ff"><span class="style37">อายุ</span></td>
            <td bgcolor="#dcf9ff"><span class="style34 style33 style38">
              <label>              </label>
              <span class="style39">
              <input name="pt_age" type="text" id="pt_age" size="20" maxlength="20" />
              </span></span></td>
          </tr>
        <tr>
          <td bgcolor="#dcf9ff"><span class="style37">ที่อยู่
            <label><font color="#FF0000">**</font></label>
  </span></td>
            <td bgcolor="#dcf9ff"><span class="style39">
              <label>
                <textarea name="pt_address" cols="60" rows="5" id="pt_address"></textarea>
              </label>
              </span></td>
          </tr>
        <tr>
          <td bgcolor="#dcf9ff"><span class="style37"> อาชีพ</span></td>
            <td bgcolor="#dcf9ff"><span class="style34 style33 style38">
              <input name="pt_occupation" type="text" id="pt_occupation" size="30" maxlength="30" />
              </span></td>
          </tr>
        <tr>
          <td bgcolor="#dcf9ff" class="style37">โทรศัพท์</td>
            <td bgcolor="#dcf9ff"><span class="style39">
              <label>
                <input name="pt_phone" type="text" id="pt_phone" size="10" maxlength="10"  onkeypress=check_number(); />
              </label>
              </span></td>
          </tr>
        <tr>
          <td bgcolor="#dcf9ff"><span class="style37">อีเมล์ </span></td>
            <td bgcolor="#dcf9ff"><span class="style34 style33 style38">
              <label>
                <input name="pt_email" type="text" id="pt_email" size="40" maxlength="40" />
                &nbsp;</label>
              </span></td>
          </tr>
        <tr>
          <td bgcolor="#dcf9ff" class="style37">ประวัติการแพ้ยา</td>
            <td bgcolor="#dcf9ff"><span class="style39">
              <textarea name="pt_drug" cols="60" rows="5" id="pt_drug"></textarea>
              </span></td>
          </tr>
        <tr>
          <td bgcolor="#dcf9ff"><span class="style37">โรคประจำตัว</span></td>
            <td bgcolor="#dcf9ff"><span class="style34 style33 style38">
              <input name="pt_disease" type="text" id="pt_disease" size="50" maxlength="50" />
              &nbsp;</span></td>
          </tr>
        <tr>
          <td bgcolor="#dcf9ff"><span class="style37">วันออกบัตร</span></td>
            <td bgcolor="#dcf9ff"><span class="style34 style33 style38">
              <input name="card_day" type="text" id="card_day" />
              <script language="JavaScript">
	new tcal ({
		// form name
		'formname': 'frmregister',
		// input name
		'controlname': 'card_day'
	});

	</script>
              &nbsp;</span></td>
          </tr>
        <tr>
          <td bgcolor="#dcf9ff"><span class="style37">หมายเหตุ</span></td>
            <td bgcolor="#dcf9ff"><span class="style34 style33 style38">
              <textarea name="pt_memo" cols="60" rows="5" id="pt_memo"></textarea>
              </span></td>
          </tr>
        <tr>
          <td colspan="2" background="image/foot.jpg"><div align="center">
            <input name="Submit2" type="submit" value="บันทึก" />
            &nbsp;
            <input type="reset" name="Submit2" value="ลบ" />
            &nbsp;
            <label></label>
            </div></td>
          </tr>
        </table>
        <p>&nbsp;</p>
      <p align="center"><a href="pt_manag_show.php"><img src="image/left.gif" width="42" height="42" border="0" /></a></p></td></tr>
  
  

  <tr>
    <td colspan="2"><? require('footer.php') ?></td>
  </tr>
</table>
<p>&nbsp;</p>
</form>
</body>
</html>


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-03-22 09:57:13 By : นก
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : จะคำนวณอายุ จากช่อง textBox ของวันเดือนปีเกิด โดยอัตโนมัตทันที ทำอย่างไรคะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

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