原型表单提交验证
我有一个 id 为“new_profile_choices”的表单,并且我正在使用 Prototype 来验证该表单。当我尝试验证表单提交事件时,它似乎没有处理该事件。你能帮我调试一下吗?
查看表单源
<form action="/polls/vote" class="new_profile_choices" id="new_profile_choices" method="post">
<input id="profile_choices_profile_id" name="profile_choices[profile_id]" type="hidden" value="2" />
<input id="profile_choices_poll_id" name="profile_choices[poll_id]" type="hidden" value="50" />
<div id="poll_error_messages">
<p>Please select a valid vote</p>
</div>
<p>
<p class="choice">
<input id="profile_choices_choice_id_80" name="profile_choices[choice_id]" type="radio" value="80" />Yes
</p>
<p class="choice">
<input id="profile_choices_choice_id_81" name="profile_choices[choice_id]" type="radio" value="81" />No
</p>
<p class="choice">
<input id="profile_choices_choice_id_82" name="profile_choices[choice_id]" type="radio" value="82" />Can't Say
</p>
</p>
<input class="r4corners" id="profile_choices_submit" name="commit" type="submit" value=" Vote " />
</form>
原型事件处理程序
$('new_profile_choices').observe("submit", function(event){
alert("form submission");
}
I have a form with id 'new_profile_choices', and I am using Prototype to validate the form. When I tried to validate the form submit event, it does not seem to handle the event. Could you please help me to debug it.
View Source of the Form
<form action="/polls/vote" class="new_profile_choices" id="new_profile_choices" method="post">
<input id="profile_choices_profile_id" name="profile_choices[profile_id]" type="hidden" value="2" />
<input id="profile_choices_poll_id" name="profile_choices[poll_id]" type="hidden" value="50" />
<div id="poll_error_messages">
<p>Please select a valid vote</p>
</div>
<p>
<p class="choice">
<input id="profile_choices_choice_id_80" name="profile_choices[choice_id]" type="radio" value="80" />Yes
</p>
<p class="choice">
<input id="profile_choices_choice_id_81" name="profile_choices[choice_id]" type="radio" value="81" />No
</p>
<p class="choice">
<input id="profile_choices_choice_id_82" name="profile_choices[choice_id]" type="radio" value="82" />Can't Say
</p>
</p>
<input class="r4corners" id="profile_choices_submit" name="commit" type="submit" value=" Vote " />
</form>
Prototype Event Handler
$('new_profile_choices').observe("submit", function(event){
alert("form submission");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的帖子中存在一个印刷错误:脚本块的末尾应该是一个右括号(关键)和一个分号(不是那么重要,但应该在那里)。而且,一切都应该在 DOM 加载之后执行(onload、ondomready):(
在这里测试一下:http:// jsfiddle.net/YuTH5/1/)
In your post is a typographic mistake: at the end of script block should be a closing parenthesis (critical) and a semicolon (not so important, but should be there). Moreover, everything should be executed after the DOM is loaded (onload, ondomready):
(test it here: http://jsfiddle.net/YuTH5/1/ )