grungefreak Posted July 8, 2009 Share Posted July 8, 2009 I want to submit a form using a link. Is this possible in Javascript? GF Quote Link to comment Share on other sites More sharing options...
corbin Posted July 9, 2009 Share Posted July 9, 2009 Yes, it's possible. You'll need to obtain a pointer to the "element" instance of the form then use the submit() method. (I don't think forms are actually "element"s in the sense that I mean, but what ever.) Like so: <html> <head> <title>Test</title> <script type="text/javascript"> <!-- function SubmitForm(form_id) { var f = document.getElementById(form_id); if(f != null) { f.submit(); } return false; } //--> </script> </head> <body> <form id="form1" method="POST" target="form_target.php"> Test: <input type="text" name="text"> </form> <a href="#" onclick="return SubmitForm('form1');">Submit</a> </body> </html> You could try styling a submit button though. Quote Link to comment Share on other sites More sharing options...
haku Posted July 9, 2009 Share Posted July 9, 2009 Forms are elements OP - making a link a submit button isn't the greatest idea, because the form won't be submittable by anyone with javascript turned off. Quote Link to comment Share on other sites More sharing options...
corbin Posted July 9, 2009 Share Posted July 9, 2009 So I guess if forms are elements (makes sense, since I think document.getElementById() always returns an element instance [or null]), then every element instance has a submit method... Weird. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.