写网页时候JavaScript代码出错

来源:百度知道 编辑:UC知道 时间:2024/05/24 09:40:34
触发代码<a href="#" onClick="chackname()">[检测用户]</a>
事件响应相应代码
function chackname()
{
alert("事件响应了");//这行测试用的
if(myform.username.value=="")
{
alert("请输入用户名!");
myform.username.foucs();
return;
}
var str ="check_username.asp?username="+myform.username.value;
window.showModalDialog(str,"","dialogWidth=400px;dialogHeight=220px;status=no;help=no;scrollbars=no");
}
出错的是这里myform.username.value
myform是表单名,username是表项。我参照标准代码写的
但是错误提示“myform.username.value为空或不是对象”
高手指点我该怎么办
PS:问题已经解决,代码都没有问题,是form名重了,换了个名就解决了。多谢各位大侠指点,小弟感激不尽

var str=document.myform.username.value;
检查下你的表单名有没有写错

myform.username.value 这个不行的。
前面要加上
“document.”

把你的html代码贴出来吧

document.myform.username.value或者document.getElementById("username").value, username最好是表单项的id

检查一下各个标签的命名是否有重的