maxwel Posted July 7, 2013 Share Posted July 7, 2013 The problem is that onclick just call the last fucntion which is button2() also tried to do it like onclick"button1(); button2();" but it do the same thing. been trying lots of ways like onsubmit but still dont work. idk why is that? <script type='text/javascript'> function submitnow(){ function OnButton1() { document.forms['form1'].action='somefile'; document.forms['form1'].target='_blank'; // Open in a new window document.forms['form1'].submit(); // Submit the page return true; } function OnButton2() { document.forms['form1'].action='somefile'; document.forms['form1'].target='_self'; // Open in a new window document.forms['form1'].submit(); // Submit the page return true; } } </script> </head> <body> <input type='hidden' name='submitted' id='submitted' value='1'/> <form enctype="multipart/form-data" method="post" id="form1" name="form1" action="somefile"> <input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $up_id; ?>"/> <input type="file" name="fileToUpload" size="40" onclick="toggle_visibility('progress_win');" id="file"/><br /> <iframe id="upload_frame" name="upload_frame" frameborder="0" border="0" src="" scrolling="no" scrollbar="no" > </iframe> <br /> <input type="submit" name="Submit" value="Upload Mix" onclick="submitnow()" /><br> can even someone write something similar to do it with ajax instead of js? cuz through searching i found that it seems to be done through ajax than js -simply i need to submit this form to 2 targets for 2 actions but it doesn't work it just submit to last function and ignore the first Quote Link to comment https://forums.phpfreaks.com/topic/279928-problem-with-calling-2-functions-with-onclick/ Share on other sites More sharing options...
codefossa Posted July 8, 2013 Share Posted July 8, 2013 Without using Ajax, you're going to cause a page load when the form submits. I'd suggest using jQuery if you wish to go that route. Check out $.post(), and you should figure it out pretty easily. They have examples on the jQuery site. Quote Link to comment https://forums.phpfreaks.com/topic/279928-problem-with-calling-2-functions-with-onclick/#findComment-1439852 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.