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 Link to comment https://forums.phpfreaks.com/topic/165260-submit-form-using-link/ 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. Link to comment https://forums.phpfreaks.com/topic/165260-submit-form-using-link/#findComment-871664 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. Link to comment https://forums.phpfreaks.com/topic/165260-submit-form-using-link/#findComment-871783 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. Link to comment https://forums.phpfreaks.com/topic/165260-submit-form-using-link/#findComment-871795 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.