2011-09-23 66 views
0

我在html中获得了一个验证用户输入的表单。问题是即使在本地主机上跳转到“操作”页面也需要很长时间。继承人的代码提交表单时的性能问题

<form action="Activity.php" method="GET" > 

<div style="display:none"> 
<input type="text" id="chapter" name="chapter"/> 
<input type="text" id="book" name="book"/> 
<input type="text" id="activity" name="activity"/> 
</div> 

<input type="image" src="includes/file.png" onClick="return validateForm()" title="Create New Activity" > 

</form> 

为validateForm的代码是:

function validateForm() 
    { 
     document.body.style.cursor='wait'; 
     if(document.getElementById("book").value==null || document.getElementById("book").value=="" 
        || document.getElementById("chapter").value==null || document.getElementById("chapter").value=="") 
     { 
      document.body.style.cursor='default'; 
      alert("You cannot create an activity at the selected location."); 
      return false; 
     } 



     var name=prompt("Please enter the New Activity Name","New Activity Name"); 
     if (name==null || name=="") 
     { 
      document.body.style.cursor='default'; 
      return false; 
     } 

     document.getElementById('activity').value=encodeURI(name); 
     return true; 

    } 

如果删除上述功能的提示,它会立即跳转到activity.php页面,但如果我保持提示,并要求活动名称,需要很长时间才能加载所需的页面(可能需要注意表单提交过程被提示中断,并且点击提示'OK'按钮提交会再次启动!!不知道:S)应该是什么一个解决方案(一个快速的)在提交表单时从用户处获得输入?谢谢!!

+0

为什么你使用'prompt'来收集信息来放置表单?你不是击败了表格的目的吗? –

+0

你的方法有太多不正确的东西。为什么不使用在表单提交时验证的标签? – pacman

+0

@pacman:我确实试过这个,看看它是否有所作为,但它的力量。我正在使用输入类型图像,我需要一个图像作为用户可以点击的按钮。 – samach

回答

0

此对象不存在:document.getElementById('activity')

+0

对不起,它确实存在!输入错误。编辑它。感谢您指出! – samach

1

试试这个。

function validateForm() 
    { 
     document.body.style.cursor='wait'; 
     if(document.getElementById("book").value || document.getElementById("chapter").value) 
     { 
      document.body.style.cursor='default'; 
      alert("You cannot create an activity at the selected location."); 
      return false; 
     } 



     var name=prompt("Please enter the New Activity Name","New Activity Name"); 
     if (name) 
     { 
      document.body.style.cursor='default'; 
      return false; 
     } 

     //document.getElementById('activity').value=encodeURI(name); 
     return true; 

    }