开发者

Submitting Form Via Javascript, form defined in external PHP file

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


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.


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:

 $('#editForm').submit();

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜