<?php echo '<span id="provinceDiv">'; echo "<label for=\"province\"></label><select name=\"province\" id=\"province\" onchage=\"dochange('province')\">\n"; echo "<option value=\"$province\">กรุณาเลือกจังหวัด</option> \n" ; echo "</select></span>\n"; ?>
function dochange( obj ) { var req = Inint_AJAX(); var province = document.getElementById( 'province' ).value; var tumbon = document.getElementById( 'tumbon' ).value; if ( obj && obj.name == 'province' ) //àÁ×èÍ·Ó¡ÒÃàÅ×Í·Õè¨Ñ§ËÇÑ´ÁÒ ãËéà¤ÅÕÂÃì¤èÒÍÓàÀÍ { var amphur = ""; } else //àÅ×Í¡ÃÒ¡ÒÃÍ×è¹ { var amphur = document.getElementById( 'amphur' ).value; }; var data = "province=" + province + "&hur=" + amphur + "&tumbon=" + tumbon; req.onreadystatechange = function() { if ( req.readyState == 4 ) { if ( req.status == 200 ) { var datas = eval( '(' + req.responseText + ')' ); // JSON document.getElementById( 'provinceDiv' ).innerHTML = datas[0].province; document.getElementById( 'amphurDiv' ).innerHTML = datas[0].amphur; document.getElementById( 'tumbonDiv' ).innerHTML = datas[0].tumbon; }; }; }; req.open( "post" , "../function/province.php" , true ); //ÊÃéÒ§ connection req.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" ); // set Header req.send( data ); //Ê觤èÒ };
<? header( "Cache-Control: no-cache, must-revalidate" ); header( "Pragma: no-cache" ); header( "content-type: application/x-javascript; charset=windows-874" ); $province = $_POST[province]; $amphur = $_POST[amphur]; $tumbon = $_POST[tumbon]; require("../connect/pconnect.php"); $sql = "SELECT ProvinceID, ProvinceName FROM province"; $result = mysql_query( $sql ); echo "[{\"province\":\""; echo "<label for='province'></label>"; echo "<select name='province' id='province' onchange='dochange(this)'>"; echo "<option value='0'>--¡ÃسÒàÅ×Í¡¨Ñ§ËÇÑ´--</option>"; while( $fetcharr = mysql_fetch_array( $result ) ) { $id = $fetcharr[ProvinceID]; $name = $fetcharr[ProvinceName]; echo "<option value='$id'"; if ( $province == $id ) //àÅ×Í¡¨Ñ§ËÇÑ´·ÕèàÅ×Í¡äÇé { echo " selected='selected'"; }; echo ">$name</option>"; }; echo "</select>\",\"amphur\":\""; echo "<label for='amphur'></label>"; echo "<select name='amphur' id='amphur' onchange='dochange(this)'>"; //¶éÒÁÕ¡ÒÃàÅ×Í¡¨Ñ§ËÇÑ´ÁÒáÅéÇãËéáÊ´§ÍÓàÀ͵èÍ if ( $province != "0" && $province != "" ) { echo "<option value='0'>--¡ÃسÒàÅ×Í¡ÍÓàÀÍ--</option>"; $sql = "SELECT AmphurID, AmphurName FROM amphur WHERE ProvinceID='$province'"; $result = mysql_query( $sql ); while( $fetcharr = mysql_fetch_array( $result ) ) { $id = $fetcharr[AmphurID]; $name = $fetcharr[AmphurName]; echo "<option value='$id'"; if ( $amphur == $id ) //àÅ×Í¡ÍÓàÀÍ·ÕèàÅ×Í¡äÇé { echo " selected='selected'"; }; echo ">$name</option>"; }; } else { echo "<option value=''>--------------</option>"; }; echo "</select>\",\"tumbon\":\""; echo "<label for='tumbon'></label>"; echo "<select name='tumbon' id='tumbon'>"; //¶éÒÁÕ¡ÒÃàÅ×Í¡ÍÓàÀÍÁÒáÅéÇãËéáÊ´§µÓºÅµèÍ if ( $amphur != "0" && $amphur != "" ) { echo "<option value='0'>--¡ÃسÒàÅ×Í¡µÓºÅ--</option>"; $sql = "SELECT TumbonID, TumbonName FROM tumbon WHERE amphurID=$amphur"; $result = mysql_query( $sql ); while( $fetcharr = mysql_fetch_array( $result ) ) { $id = $fetcharr[TumbonID]; $name = $fetcharr[TumbonName]; echo "<option value='$id'"; if ( $tumbon == $id ) //àÅ×Í¡µÓºÅ·ÕèàÅ×Í¡äÇé { echo " selected='selected'"; }; echo ">$name</option>"; }; } else { echo "<option value=''>--------------</option>"; }; echo "</select>\"}]"; mysql_close(); ?>
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง