1

Here's my code:

function checkupload(){ if(upload == false) { alert("Please upload a file"); return false; } (...) $('#download_form').submit(); alert('submitted'); } My HTML: <form action="http://localhost/rendu/download.php" method="post" id="download_form"> <input type="hidden" name="57" id="in_57"/> <input type="hidden" name="72" id="in_72"/> <input type="hidden" name="png" id="in_png"/> <input type="hidden" name="ico" id="in_ico"/> <a onclick='checkupload()'><img src="images/download_normal.png" onmouseover="mover()" onmouseout="mout()"/></a> </form> 

No matter what I do the form won't get submitted. I've taken a look at the requests and there's no request sent to the download.php page, but the alert message is displayed.

What am I missing? Thanks.

3
  • it's defined earlier in the code. There is no error in the console. Commented Oct 9, 2012 at 19:11
  • jsfiddle from cljk answer below ( jsfiddle.net/FXd8p ) reproduces your code, and the form submits. So there must be something else we are not aware of. Commented Oct 9, 2012 at 19:14
  • I'm using Google Chrome Version 23.0.1255.0 (154635) Commented Oct 9, 2012 at 19:19

2 Answers 2

2

You mixed up two things: binding to the event-handler and calling the form submission.

Compare http://jsfiddle.net/FXd8p/

and http://api.jquery.com/submit/

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

2 Comments

I think you're right. Then how can I submit a form from JavaScript?
Your current version (using submit()) should work - but check the console. Perhaps "upload" (line 2) is not defined elsewhere and the script fails.
1

Call submit without putting alert into it.

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

4 Comments

That's what I did on the first place but the result is the same.
@Adil: nobody's going to be able to visit a site on your localhost.
Yes I made another html page which works fine with this code: <form action="localhost/rendu/download.php" method="post"> <input type="submit"/> </form>
Yes true @calvinf, I just want to make sure he has the valid url.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.