0

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

4
  • Can't do much without seeing your code. Commented Mar 27, 2011 at 0:54
  • Judging by the colour coding of the source you have posted there appears to be some HTML errors - lack of spaces between element attributes, which could be tripping up the processing of the DOM correctly. Commented Mar 27, 2011 at 1:08
  • Do your alert also reaches the else statement where the form will submit? Ever try to use firebug or chrome developer tools. Have a try to see if you encounter a javascript error. Commented Mar 27, 2011 at 1:24
  • The alert in the final else statement of the EditFormSubmit() function does fire correctly. Commented Mar 27, 2011 at 10:32

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

4 Comments

I tried using a jquery selector earlier (which is why the form has an id). As 'w3d' mentioned, the syntnax highlighting went abit funny around the form, so I made sure there were spaces between all the attributes but still no luck. So there is nothing wrong with my submit/validation approach, but there must be a syntax error muddled in there somewhere you think?
Here is the php function used to spit out the form into the main index file pastebin.com/hPnZQgTs
I did notice that you are missing a semicolon on the '·' character.
This is the javascript error I see 'Uncaught TypeError: Property 'submit' of object #<HTMLFormElement> is not a function' in chrome.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.