|
|
|
ถ้าไม่ได้แก้ไขข้อมูลต้องแจ้งให้ทราบ เช็คยังไงค่ะ |
|
|
|
|
|
|
|
แก้ไขโค้ดจาก http://www.aspdeveloper.net/tiki-index.php?page=HTMLTipsCheckIfFormDirty ครับ
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>untitled</title>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620" />
<script>
function form_is_modified(oForm)
{
var el, opt, hasDefault, i = 0, j;
while (el = oForm.elements[i++]) {
switch (el.type) {
case 'text' :
case 'textarea' :
case 'hidden' :
if (!/^\s*$/.test(el.value) && el.value != el.defaultValue) return true;
break;
case 'checkbox' :
case 'radio' :
if (el.checked != el.defaultChecked) return true;
break;
case 'select-one' :
case 'select-multiple' :
j = 0, hasDefault = false;
while (opt = el.options[j++])
if (opt.defaultSelected) hasDefault = true;
j = hasDefault ? 0 : 1;
while (opt = el.options[j++])
if (opt.selected != opt.defaultSelected) return true;
break;
}
}
return false;
}
function test(){
if (form_is_modified(document.forms[0])){
return true;
}else{
alert('ยังไม่ได้แก้ไข');
return false;
}
}
</script>
</head>
<body>
<form action="?" onsubmit="return test();">
<input type="text" />
<textarea rows="3" cols="8"></textarea>
<input type="hidden" value="foo" />
<input type="checkbox" checked="checked" />
<input type="checkbox" />
<input type="radio" name="r1" checked="checked" />
<input type="radio" name="r1" />
<select>
<option value="1">blah 1</option>
<option value="2">blah 2</option>
<option value="3">blah 3</option>
</select>
<select multiple="multiple">
<option value="4">blah 1</option>
<option value="5" selected="selected">blah 2</option>
<option value="6" selected="selected">blah 3</option>
</select>
<br /><br /><br />
<input type="submit" value="DONE" />
</form>
</body>
</html>
|
|
|
|
|
Date :
2009-06-23 07:31:41 |
By :
num |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณ คุณ num มากนะค่ะ
|
|
|
|
|
Date :
2009-06-23 13:28:45 |
By :
doramelovely |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|