通过 Javascript 提交表单,表单在外部 PHP 文件中定义
我有一个通过 php 注入到页面主体中的表单。我有一个触发 javascript 验证功能的按钮,最后它应该提交表单,但它似乎不想提交。
我正在使用函数调用:
document.myform.submit();
脚本肯定会到达此函数调用,因为我成功弹出了调试警报()消息。它位于 validate&submit 函数中,该函数在 jquery $(document).ready() 函数之后定义。
我已经检查了所有明显的事情,例如表单标签正确打开/关闭、表单名称正确等,但我似乎无法解决问题。
有什么想法吗?我还没有提交整个文件,因为它混杂着其他东西,但如果需要的话我可以提交。
非常感谢, Oliver
这是 php 完成其工作后的 html 源代码: http://pastebin.com/2EaucEar
I have a form which is injected into the page body via php. I have a button which triggers a javascript validation function, and at the end it should submit the form but it doesn't seem to want to submit.
I'm using the function call:
document.myform.submit();
The script definitely reaches this function call, as I have a debug alert() message pop up successfully. Its located in a validate&submit function which is defined after a jquery $(document).ready() function.
I've checked all the obvious things like form tags opened/closed properly, form name correct etc but I can't seem to work out the problem.
Any ideas? I haven't submitted the whole file as its cluttered with other stuff, but I can if needed.
Many Thanks,
Oliver
Heres the html source after php has done its thing: http://pastebin.com/2EaucEar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
找到了!
我正在使用一个看起来像普通链接的按钮,但没有使用任何按钮功能。所以它也可能是一个链接。按钮的名称是name='submit',这对我来说非常有意义,但我通过设置type='button'来确保它不是提交按钮>。
看来submit是一个关键字,并将按钮转换为提交什么的。不完全确定,但将按钮名称(我在代码的其余部分中没有提及)更改为其他名称可以解决问题。
谢谢你们的帮助。你帮我缩小了范围。
Found it!
I'm using a button which is made to look like a normal link, but not using any of the button features. So it might as well be a link. The name of the button was name='submit' which made perfect sense to me, but I made sure it wasn't a submit button by setting the type='button'.
It seems submit is a keyword, and cast the button as a submit or something. Not entirely sure, but changing the button name (which I don't refer to in the rest of the code) to something else fixed the problem.
Thanks for your help guys. You helped me narrow it down.
我做了一些修补。当我最终到达调用您的提交行的地方时,我收到了 javascript 错误。由于您使用的是 jQuery,请尝试使用以下内容:
如果有帮助,这里是我用来修改的 jsFiddle。
http://jsfiddle.net/CkvLj/7/
希望这会有所帮助。
鲍勃
I have done a bit of tinkering. When I finally got to the point where your submit line is called, I got a javascript error. Since you are using jQuery, try using the following:
If it helps any, here is the jsFiddle that I was using to tinker around with.
http://jsfiddle.net/CkvLj/7/
Hope this helps.
Bob