|
|
|
อยากให้จังหวัดและอำเภอ ที่มาจากasp+xml ไม่เป็น id เป็นตัวอักษรเลยได้มั้ยครับ |
|
|
|
|
|
|
|
อยากให้จังหวัดและอำเภอ ที่มาจากasp+xml ไม่เป็น id เป็นตัวอักษรเลยได้มั้ยครับ
ผลลัพธ์
page_add.asp
Code (ASP)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script type="text/javascript" src="AutoProvince.js"></script>
<script>
$('body').AutoProvince({
PROVINCE: '#province', // select div สำหรับรายชื่อจังหวัด
AMPHUR: '#amphur', // select div สำหรับรายชื่ออำเภอ
DISTRICT: '#district', // select div สำหรับรายชื่อตำบล
POSTCODE: '#postcode', // input field สำหรับรายชื่อรหัสไปรษณีย์
arrangeByName: false // กำหนดให้เรียงตามตัวอักษร
});
</script>
<!--#include file="bar.asp"-->
<form action="AspAccessAddSave.asp" name="frmAdd" method="post">
<table width="600" border="1">
<tr>
<th width="100%"> <div align="center">Code </div></th>
<th width="100%"> <div align="center">SchoolName </div></th>
<th width="200"> <div align="center">Zone </div></th>
<th width="198"> <div align="center">Amphur </div></th>
<!-- <th width="198"> <div align="center">zipcode </div></th> -->
<!-- <th width="198"> <div align="center">tambon </div></th> -->
<th width="70"> <div align="center">CourseStatus </div></th>
<th width="70"> <div align="center">RegStatus </div></th>
</tr>
<tr>
<td><div align="center">
<input type="text" name="txtCode" size="20">
</div></td>
<td><input type="text" name="txtSchoolName" size="20"></td>
<td>
<select id="province"name="txtprovince">
<option>- กรุณาเลือกจังหวัด -</option>
</select> </td>
<td>
<select id="amphur"name="txtamphur">
<option>- กรุณาเลือกอำเภอ -</option>
</select>
<!-- <td><input type="text" id="postcode" /></td></td>-->
<!-- <td> <select id="district">
<option>- กรุณาเลือกตำบล -</option>
</select> </td> -->
<td > <select name="txtCourseStatus">
<option value="0">0</option>
<option value="1">1</option>
</select></td>
<td ><input type="text" name="txtRegStatus" size="20" value="1" readonly></td>
</tr>
</table>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
AspAccessAddSave.asp
Code (ASP)
<% Option Explicit %>
<html>
<head>
</head>
<!--#include file="bar.asp"-->
<!--#include file="config.asp"-->
<body>
<%
Dim Conn,strSQL,objExec
strSQL = ""
strSQL = strSQL &"INSERT INTO School "
strSQL = strSQL &"(Code,SchoolName,Amphur,Zone,CourseStatus,RegStatus) "
strSQL = strSQL &"VALUES "
strSQL = strSQL &"('"&Request.Form("txtCode")&"','"&Request.Form("txtSchoolName")&"','"&Request.Form("txtamphur")&"' "
strSQL = strSQL &",'"&Request.Form("txtprovince")&"','"&Request.Form("txtCourseStatus")&"','"&Request.Form("txtRegStatus")&"') "
Set objExec = Conn.Execute(strSQL)
If Err.Number = 0 Then
Response.write("Save Done.")
Else
Response.write("Error Save ["&strSQL&"] ("&Err.Description&")")
End If
Conn.Close()
Set objExec = Nothing
Set Conn = Nothing
%>
</body>
</html>
thailand.xml ฉบับย่อ
Code (XML)
<?xml version="1.0" encoding="utf-8"?>
<!--
- phpMyAdmin XML Dump
- version 3.5.1
- http://www.phpmyadmin.net
-
- Host: localhost
- Generation Time: Aug 12, 2016 at 10:35 AM
- Server version: 5.5.25
- PHP Version: 5.4.4
-->
<pma_xml_export version="1.0" xmlns:pma="http://www.phpmyadmin.net/some_doc_url/">
<!--
- Structure schemas
-->
<pma:structure_schemas>
<pma:database name="thailand" collation="utf8_general_ci" charset="utf8">
<pma:table name="amphur">
CREATE TABLE `amphur` (
`AMPHUR_ID` int(5) NOT NULL AUTO_INCREMENT,
`AMPHUR_CODE` varchar(4) COLLATE utf8_unicode_ci NOT NULL,
`AMPHUR_NAME` varchar(150) COLLATE utf8_unicode_ci NOT NULL,
`POSTCODE` varchar(5) COLLATE utf8_unicode_ci NOT NULL,
`GEO_ID` int(5) NOT NULL DEFAULT '0',
`PROVINCE_ID` int(5) NOT NULL DEFAULT '0',
PRIMARY KEY (`AMPHUR_ID`)
) ENGINE=MyISAM AUTO_INCREMENT=999 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
</pma:table>
<pma:table name="district">
CREATE TABLE `district` (
`DISTRICT_ID` int(5) NOT NULL AUTO_INCREMENT,
`DISTRICT_CODE` varchar(6) COLLATE utf8_unicode_ci NOT NULL,
`DISTRICT_NAME` varchar(150) COLLATE utf8_unicode_ci NOT NULL,
`AMPHUR_ID` int(5) NOT NULL DEFAULT '0',
`PROVINCE_ID` int(5) NOT NULL DEFAULT '0',
`GEO_ID` int(5) NOT NULL DEFAULT '0',
PRIMARY KEY (`DISTRICT_ID`)
) ENGINE=MyISAM AUTO_INCREMENT=8861 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
</pma:table>
<pma:table name="geography">
CREATE TABLE `geography` (
`GEO_ID` int(5) NOT NULL AUTO_INCREMENT,
`GEO_NAME` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`GEO_ID`)
) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
</pma:table>
<pma:table name="province">
CREATE TABLE `province` (
`PROVINCE_ID` int(5) NOT NULL AUTO_INCREMENT,
`PROVINCE_CODE` varchar(2) COLLATE utf8_unicode_ci NOT NULL,
`PROVINCE_NAME` varchar(150) COLLATE utf8_unicode_ci NOT NULL,
`GEO_ID` int(5) NOT NULL DEFAULT '0',
PRIMARY KEY (`PROVINCE_ID`)
) ENGINE=MyISAM AUTO_INCREMENT=78 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
</pma:table>
</pma:database>
</pma:structure_schemas>
<!--
- Database: 'thailand'
-->
<database name="thailand">
<!-- Table amphur -->
<table name="amphur">
<column name="AMPHUR_ID">1</column>
<column name="AMPHUR_CODE">1001</column>
<column name="AMPHUR_NAME">เขตพระนคร </column>
<column name="POSTCODE">10200</column>
<column name="GEO_ID">2</column>
<column name="PROVINCE_ID">1</column>
</table>
<table name="amphur">
<column name="AMPHUR_ID">2</column>
<column name="AMPHUR_CODE">1002</column>
<column name="AMPHUR_NAME">เขตดุสิต </column>
<column name="POSTCODE">10300</column>
<column name="GEO_ID">2</column>
<column name="PROVINCE_ID">1</column>
</table>
<table name="amphur">
<column name="AMPHUR_ID">3</column>
<column name="AMPHUR_CODE">1003</column>
<column name="AMPHUR_NAME">เขตหนองจอก </column>
<column name="POSTCODE">10530</column>
<column name="GEO_ID">2</column>
<column name="PROVINCE_ID">1</column>
</table>
<table name="amphur">
<column name="AMPHUR_ID">4</column>
<column name="AMPHUR_CODE">1004</column>
<column name="AMPHUR_NAME">เขตบางรัก </column>
<column name="POSTCODE">10500</column>
<column name="GEO_ID">2</column>
<column name="PROVINCE_ID">1</column>
</table>
AutoProvince.js
Code (JavaScript)
/*
Author : Witoon Pomipon
Email : [email protected]
Website : codebee.co.th
Company : codebee company limited
*/
;(function( $ ){
$.fn.AutoProvince = function( options ) {
var Setting = $.extend( {
PROVINCE: '#province', // select div สำหรับรายชื่อจังหวัด
AMPHUR: '#amphur', // select div สำหรับรายชื่ออำเภอ
DISTRICT: '#district', // select div สำหรับรายชื่อตำบล
POSTCODE: '#postcode', // input field สำหรับรายชื่อรหัสไปรษณีย์
arrangeByName: false // กำหนดให้เรียงตามตัวอักษร
}, options);
return this.each(function() {
var xml;
var dataUrl = "thailand.xml";
$(function() {
initialize();
});
function initialize(){
$.ajax({
type: "GET",
url: dataUrl,
dataType: "xml",
success: function(xmlDoc) {
xml = $(xmlDoc);
_loadProvince();
addEventList();
},
error: function() {
console.log("Failed to get xml");
}
});
}
function _loadProvince()
{
var list = [];
xml.find('table').each(function(index){
if($(this).attr("name") == Setting.PROVINCE.split("#")[1]){
var PROVINCE_ID = $(this).children().eq(0).text();
var PROVINCE_NAME = $(this).children().eq(2).text();
if(PROVINCE_ID)list.push({id:PROVINCE_ID,name:PROVINCE_NAME});
}
});
if(Setting.arrangeByName){
AddToView(list.sort(SortByName),Setting.PROVINCE);
}else{
AddToView(list,Setting.PROVINCE);
}
}
function _loadAmphur(PROVINCE_ID_SELECTED)
{
var list = [];
var isFirst = true;
$(Setting.AMPHUR).empty();
xml.find('table').each(function(index){
if($(this).attr("name") == Setting.AMPHUR.split("#")[1]){
var AMPHUR_ID = $(this).children().eq(0).text();
var AMPHUR_NAME = $(this).children().eq(2).text();
var POSTCODE = $(this).children().eq(3).text();
var PROVINCE_ID = $(this).children().eq(5).text();
if(PROVINCE_ID_SELECTED == PROVINCE_ID && AMPHUR_ID){
if(isFirst)_loadDistrict(AMPHUR_ID);
isFirst = false;
list.push({id:AMPHUR_ID,name:AMPHUR_NAME,postcode:POSTCODE});
$(Setting.POSTCODE).val(POSTCODE);
}
}
});
if(Setting.arrangeByName){
AddToView(list.sort(SortByName),Setting.AMPHUR);
}else{
AddToView(list,Setting.AMPHUR);
}
}
function _loadDistrict(AMPHUR_ID_SELECTED)
{
var list = [];
$(Setting.DISTRICT).empty();
xml.find('table').each(function(index){
if($(this).attr("name") == Setting.DISTRICT.split("#")[1]){
var DISTRICT_ID = $(this).children().eq(0).text();
var DISTRICT_NAME = $(this).children().eq(2).text();
var AMPHUR_ID = $(this).children().eq(3).text();
if(AMPHUR_ID_SELECTED == AMPHUR_ID && DISTRICT_ID){
list.push({id:DISTRICT_ID,name:DISTRICT_NAME});
}
}
});
if(Setting.arrangeByName){
AddToView(list.sort(SortByName),Setting.DISTRICT);
}else{
AddToView(list,Setting.DISTRICT);
}
}
function addEventList(){
$(Setting.PROVINCE).change(function(e) {
var PROVINCE_ID = $(this).val();
_loadAmphur(PROVINCE_ID);
});
$(Setting.AMPHUR).change(function(e) {
var AMPHUR_ID = $(this).val();
$(Setting.POSTCODE).val($(this).find('option:selected').attr("POSTCODE"));
_loadDistrict(AMPHUR_ID);
});
}
function AddToView(list,key){
for (var i = 0;i<list.length;i++) {
if(key != Setting.AMPHUR){
$(key).append("<option value='"+list[i].id+"'>"+list[i].name+"</option>");
}else{
$(key).append("<option value='"+list[i].id+"' POSTCODE='"+list[i].postcode+"'>"+list[i].name+"</option>");
}
}
}
function SortByName(a, b){
var aName = a.name.toLowerCase();
var bName = b.name.toLowerCase();
return ((aName < bName) ? -1 : ((aName > bName) ? 1 : 0));
}
});
};
})( jQuery );
Tag : ASP, Ms Access, JavaScript
|
|
|
|
|
|
Date :
2018-03-24 12:25:56 |
By :
shiowa |
View :
2817 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hellowoorld
|
|
|
|
|
Date :
2018-03-26 08:16:23 |
By :
shiowa |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AutoProvince.js
Code (JavaScript) บรรทัด 123
เปลี่ยน
<option value='"+list[i].id+"'>"+list[i].name+"</option>
เป็น
<option value='"+list[i].name+"'>"+list[i].name+"</option>
ลองดูครับ
|
|
|
|
|
Date :
2018-04-19 11:21:59 |
By :
piyawat12345 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2018-06-28 21:48:10 |
By :
jojo83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|