แสดงบทความที่มีป้ายกำกับ js แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ js แสดงบทความทั้งหมด

วันจันทร์ที่ 17 มกราคม พ.ศ. 2554

javascript เปลี่ยนเป็น tab เป็น enter

โค้ด javascript เปลี่ยน tab เป็น enter ครับ

<html>
<head>
<script>
function handleEnter(event){
var e=window.event?window.event:event;
var keyCode=e.keyCode?e.keyCode:e.which?e.which:e.charCode;
if (keyCode == 13){
if (this.className && this.className=='last'){
this.form.submit();
return true;
}
var i;
for (i = 0; i < this.form.elements.length; i++)
if (this == this.form.elements[i])
break;
if (this.type=='textarea' && e.shiftKey)
return true;
else if (this.type=='radio')
this.form.elements[i+this.form.elements[this.name].length].focus();
else
this.form.elements[i+1].focus();
return false;
}
else
return true;
}

window.onload=function(){
var a=document.formA;
for(var i=0;i<a.elements.length;i++){
var e=a.elements[i];
e.onkeypress=handleEnter;
}
}

</script>
</head>
<body>
<?php echo 'random='.rand(1,200); ?>

<form name="formA">
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" class='last' />
<input type="submit" value="submit" />
</form>

</body>
</html>


วันศุกร์ที่ 17 ธันวาคม พ.ศ. 2553

popup windows close and refresh opener window

test.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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>test</title>
</head>

<body>

<div><?php echo date('H:i:s');?></div>

<button onclick="var w=window.open('popup.php','popup_name','width=850,height=300');w.focus();">Open Popup</button>

</body>
</html>


popup.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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>pop up</title>
</head>

<body>

<?php if (!empty($_POST['test'])) echo "name={$_POST['test']}";?>

<form method="post">

<input type="text" name="test" />
<input type="submit"/>
</form>

<button onclick="opener.location=opener.location.toString();self.close();">Close</button>

</body>
</html>

วันพฤหัสบดีที่ 25 พฤศจิกายน พ.ศ. 2553

javascript only number ควบคุมให้ป้อนข้อมูลได้เฉพาะตัวเลขเท่านั้น

นำเสนอสองวิธีการในการควบคุมครับ วิธีแรก replaceDigit เป็นการแทนค่า string ที่ผู้ใช้ป้อนเข้าไปครับ
วิธีที่สองเป็น appeptOnlyDigit จะยอมรับคำสั่งที่ป้อนมาทาง keyboard เฉพาะตัวเลขและรหัสควบคุมบางตัวเท่านั้นครับ
ทั้งสองวิธียังไม่ได้กันการ copy และ paste นะครับในส่วนนี้ต้องหาทางแก้ไขเพิ่มเติมครับ

<!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" dir="ltr" lang="th" xml:lang="th">
<head>
<meta http-equiv="content-type" content="text/html; charset=tis-620" />
<title>javascript only digit textbox</title>
<script type="text/javascript">
//<![CDATA[
function replaceDigit(el){
el.value=el.value.replace(/\D/,'');
}
function acceptOnlyDigit(event,el){
var e=window.event?window.event:event;
var keyCode=e.keyCode?e.keyCode:e.which?e.which:e.charCode;
//0-9 (numpad,keyboard)
if ((keyCode>=96 && keyCode<=105)||(keyCode>=48 && keyCode<=57)){
return true;
}
//backspace,delete,left,right,home,end
if (',8,46,37,39,36,35,'.indexOf(','+keyCode+',')!=-1){
return true;
}
return false;
}
//]]>
</script>
</head>
<body>


<form method="post" action="?" id="box">
<br/>replace digit: <input type="text" name="onlydigit" value="" onkeyup="replaceDigit(this)" />
<br/>accept only digit: <input type="text" name="onlydigit2" value="" onkeydown="return acceptOnlyDigit(event,this)" />
</form>

</body>
</html>

วันพุธที่ 13 ตุลาคม พ.ศ. 2553

jquery plugin ที่น่าสนใจ

improve-jquery-tips
lightbox
alert
create slide show
curvycorner
fancy thumbnail hover
sifr
uploadify
jcrop
auto-province
image-color
impromptu
cycle
image-dropdown
multi-level-menu
fisheye menu
gps

http://www.thaicreate.com/outling.aspx?l=http://dhtmlx.com/docs/products/dhtmlxGrid/
http://www.learningjquery.com/2009/07/setting-up-visual-studio-intellisense-for-jquery
http://www.javascripttoolbox.com/jquery/cheatsheet/
http://www.demoncodez.com/component/tag/ajax.html
http://www.longtailvideo.com
http://code.google.com/p/flot/
http://www.ryancooper.com/resources/keycode.asp
http://www.tareeinternet.com/scripts/comparison-tool/
http://htmlpurifier.org/
http://www.ziddu.com/download/7770677/jquery-form-validation-01.zip.html

function php ใน javascript

http://phpjs.org