|
 |
|
ช่วยผมหน่อยครับติดมาหลายวันแล้ว เรื่อง Select/Listmenu |
|
 |
|
|
 |
 |
|
ช่วยผมหน่อยครับติดมาหลายวันแล้ว เรื่อง Select/Listmenu คือผมต้องการให้ select value = 1 ให้ alert = 2012-5-03 (1วัน) ถ้า select value = 2 ให้ alert = 2012-6-03 (1เดือน) ถ้า select value = 3 ให้ alert = 2013-5-03 (1ปี)
[font=Verdana]อันนี้โค้ดครับ
[/font]
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<select name="select" id="select" onChange="JavaScript:fncAlert();">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<?php
//$select=2;
echo "$select";
$today=date("Y-m-d");
$month2=date("m"); //สร้างค่าเดือนปัจจุบัน
$day2=date("d"); //สร้างค่าย้อนหลังไป 5 วัน
$year2=date("Y"); //สร้างค่าปีปัจจุบัน
//$mk_data=mktime(22, 15, 10, $month, $day, $year); //กำหนดค่าโดย mktime
//echo date("M-d-Y", $mk_data); //แสดงผลโดย Format M-d-Y
if($select ==3)
{
$year2=date("Y")+1;
$mk_data=mktime(22, 15, 10, $month2, $day2, $year2);
$expire_date=date("Y-m-d", $mk_data);
}
if($select ==2)
{
$month2=date("m")+1;
$mk_data=mktime(22, 15, 10, $month2, $day2, $year2);
$expire_date=date("Y-m-d", $mk_data);
}
if($select ==1)
{
$expire_date="$today";
}
?>
<script language="javascript">
function fncAlert()
{
alert('<?=$expire_date?>');
}
</script>
</body>
</html>
ขอบพระคุณล่วงหน้าครับ
Tag : PHP, JavaScript

|
ประวัติการแก้ไข 2012-05-04 00:33:20 2012-05-04 00:34:07
|
 |
 |
 |
 |
Date :
2012-05-03 22:10:56 |
By :
loh_ittechnic |
View :
1067 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จริงๆแล้วเขียนได้หลายแบบครับ ขอเป็นอีกหนึ่งทางเลือกครับ
Code (PHP)
<html>
<head>
<title>https://www.thaicreate.com/php/forum/077951.htmll</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script language="javascript">
$(document).ready(function(){
$("select#selectDate").change(function(){
var index = $("select#selectDate option:selected").val();
var alertString = $("div#"+index).text();
alert(alertString);
});
});
</script>
</head>
<body>
<select name="select" id="selectDate" onChange="JavaScript:fncAlert();">
<option value="0">กรุณาเลือก</option>
<option value="1">ปัจจุบัน</option>
<option value="2">เดือนหน้า</option>
<option value="3">ปีหน้า</option>
</select>
<?php
$date = new DateTime(date("Y-m-d"));
$curdate = $date->format('Y-m-d');
$date->modify('+1 month');
$nextmonth = $date->format('Y-m-d');
$date->modify('+11 month');
$nextyear = $date->format('Y-m-d');
echo "<div id=\"0\" style=\"display:none;\">กรุณาเลือกสักตัวน่ะค่ะ</div>\n";
echo "<div id=\"1\" style=\"display:none;\">$curdate</div>\n";
echo "<div id=\"2\" style=\"display:none;\">$nextmonth</div>\n";
echo "<div id=\"3\" style=\"display:none;\">$nextyear</div>\n";
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2012-05-04 01:59:13 |
By :
sakuraei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|