php表单初始化
转载请注明来源:https://www.cnblogs.com/hookjc/
//初始化表单值的函数function InitForm($row,$form="form1")
{
if(count($row)<=0||!$row) return;
echo "<script>\n var f=document;\n";
$str1=" var initinputarray=new Array(";
$str2=" var initdataarray=new Array(";
for($i=0;$i<count($row);$i++)
{
$value = current($row);
$object=key($row);
if(is_numeric($object)||$object=="SID"||$object=="PHPSESSID"){next($row);continue;}//过滤数字类型的下标
$value=str_replace("\r","\\r",$value);
$value=str_replace("\n","\\n",$value);
//$value=str_replace("'","\\'",$value);
$value=str_replace("'","\'",$value);
$value=str_replace("\\\\","\\",$value);
//if(strlen($value)>0)
$str1.="'".$object."',";
$str2.="'".$value."',";
// echo "if(typeof(f.$object)!='undefined') {if('checkbox'==f.$object.type) f.$object.checked=true; else f.$object.value='".$value."';}\n";
next($row);
}
$str1.="'0')";
$str2.="'0')";
echo " $str1;\n $str2;\n for(i=0;i<initinputarray.length-1;i++) {var o=f.getElementById(initinputarray[i]);if(o!=null&&typeof(o)!='undefined') {if('checkbox'==o.type) o.checked=true; else o.value=initdataarray[i];}}</script>\n";
}