Niixie Posted July 7, 2011 Share Posted July 7, 2011 Hey freaks! I have tried to make a javascript function that should submit the form its triggered from, which means, if the function is called from form thats named updateform, it should submit that form when pressing on a link. ATM. i have nothing, i just deleted it all because of bugs. I hope you can help me! Quote Link to comment https://forums.phpfreaks.com/topic/241338-submit-form-with-javascript/ Share on other sites More sharing options...
AyKay47 Posted July 7, 2011 Share Posted July 7, 2011 you don't have any code at all to get us started? Quote Link to comment https://forums.phpfreaks.com/topic/241338-submit-form-with-javascript/#findComment-1239672 Share on other sites More sharing options...
Adam Posted July 7, 2011 Share Posted July 7, 2011 I have tried to make a javascript function that should submit the form its triggered from You're not making much sense. You want to .. trigger the submit event of a form, when it's submitted? if the function is called from form thats named updateform, it should submit that form when pressing on a link Where does the link come into it? Which link(s) should trigger the submit? You need to be more clear. Quote Link to comment https://forums.phpfreaks.com/topic/241338-submit-form-with-javascript/#findComment-1239673 Share on other sites More sharing options...
Niixie Posted July 7, 2011 Author Share Posted July 7, 2011 I'm sorry, here's a snippet of my code. <form id="updateform" name="updateform" action="lipsum.php" method="POST"> <table border="0"> <tbody> <tr> <td><label>Navn:</label></td> <td><input type="text" name="updatename" value="" /></td> </tr> <tr> <td>E-mail:</td> <td><input type="text" name="updateemail" value="" /></td> </tr> <tr> <td></td> <td> <a href="" class="button"> <span class="send">Tilmeld opdateringsmail</span> </a> </td> </tr> </tbody> </table> </form> When pressing on "Tilmeld opdateringsmail", it should redirect to lipsum.php as it says in the form tag? Quote Link to comment https://forums.phpfreaks.com/topic/241338-submit-form-with-javascript/#findComment-1239696 Share on other sites More sharing options...
AyKay47 Posted July 7, 2011 Share Posted July 7, 2011 no, not without an input with a type "submit". unless you are using javascript to submit the form...in that case we will need to see your JS if you are still having trouble Quote Link to comment https://forums.phpfreaks.com/topic/241338-submit-form-with-javascript/#findComment-1239705 Share on other sites More sharing options...
Niixie Posted July 7, 2011 Author Share Posted July 7, 2011 I dont have any code in javascript, i deleted it all because it didnt work. Quote Link to comment https://forums.phpfreaks.com/topic/241338-submit-form-with-javascript/#findComment-1239747 Share on other sites More sharing options...
AyKay47 Posted July 7, 2011 Share Posted July 7, 2011 which route are you going to go, the html method or the javascript method? Quote Link to comment https://forums.phpfreaks.com/topic/241338-submit-form-with-javascript/#findComment-1239751 Share on other sites More sharing options...
Niixie Posted July 7, 2011 Author Share Posted July 7, 2011 Javascript? -It's the only "route" i can go if i want it this way. Quote Link to comment https://forums.phpfreaks.com/topic/241338-submit-form-with-javascript/#findComment-1239752 Share on other sites More sharing options...
AyKay47 Posted July 7, 2011 Share Posted July 7, 2011 <head> <script type="text/javascript"> function submitForm(){ document.updateform.submit(); } </script> </head> <body> <form id="updateform" name="updateform" action="lipsum.php" method="POST"> <table border="0"> <tbody> <tr> <td><label>Navn:</label></td> <td><input type="text" name="updatename" value="" /></td> </tr> <tr> <td>E-mail:</td> <td><input type="text" name="updateemail" value="" /></td> </tr> <tr> <td></td> <td> <a href="" class="button"> <span class="send" onclick="submitForm()" onsubmit="this.disabled=true;return true">Tilmeld opdateringsmail</span> </a> </td> </tr> </tbody> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/241338-submit-form-with-javascript/#findComment-1239763 Share on other sites More sharing options...
Adam Posted July 7, 2011 Share Posted July 7, 2011 which route are you going to go, the html method or the javascript method? When I read that I thought you were meaning the purely JavaScript method. Yours is in-fact still mixed HTML and JavaScript. Quote Link to comment https://forums.phpfreaks.com/topic/241338-submit-form-with-javascript/#findComment-1239841 Share on other sites More sharing options...
AyKay47 Posted July 8, 2011 Share Posted July 8, 2011 which route are you going to go, the html method or the javascript method? When I read that I thought you were meaning the purely JavaScript method. Yours is in-fact still mixed HTML and JavaScript. yeah good catch and you're right...lol I guess I really meant the strictly HTML method or using javascript as well...although I could have used purely javascript... OP if you would prefer the purely javascript way let us know....good catch MrAdam thanks Quote Link to comment https://forums.phpfreaks.com/topic/241338-submit-form-with-javascript/#findComment-1239900 Share on other sites More sharing options...
Niixie Posted July 8, 2011 Author Share Posted July 8, 2011 Thanks for the function, but i have one question? function submitForm(form){ document.form.submit(); } Is that possible? Because, then i can use it at every form i need it. And also, how should it be in the link? <a href="javascript:submitForm(updateform);">Send</a> or <a href="javascript:submitForm('updateform');">Send</a> Or should it even be onClick? Quote Link to comment https://forums.phpfreaks.com/topic/241338-submit-form-with-javascript/#findComment-1240001 Share on other sites More sharing options...
Adam Posted July 8, 2011 Share Posted July 8, 2011 You would need to access the form through the forms array: document.forms[form].submit(); Otherwise JS will try to look for a form named "form". I wouldn't advise using a link to submit the form though, as users with JS disabled won't be able to use it and you'll have no fall back. More and more common these days, with mobile devices and users trying to combat pop-ups and such. What's wrong with the fully supported submit button? You can even style it to look and behave like a link if you prefer: <style type="text/css"> input.link-submit { background: transparent; border: 0; color: blue; cursor: pointer; display: inline; text-decoration: none; } input.link-submit:hover { text-decoration: underline; } </style> <input type="submit" class="link-submit" value="Send" /> Quote Link to comment https://forums.phpfreaks.com/topic/241338-submit-form-with-javascript/#findComment-1240015 Share on other sites More sharing options...
Niixie Posted July 8, 2011 Author Share Posted July 8, 2011 Maybe i'd use that insted, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/241338-submit-form-with-javascript/#findComment-1240021 Share on other sites More sharing options...
AyKay47 Posted July 8, 2011 Share Posted July 8, 2011 Maybe i'd use that insted, thanks! that's what I asked you in the beginning! Quote Link to comment https://forums.phpfreaks.com/topic/241338-submit-form-with-javascript/#findComment-1240055 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.