Jump to content

problem with calling 2 functions with onclick


maxwel

Recommended Posts

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


Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.