views:

44

answers:

1

I have a form and then a JS function which processes it and does 3 actions. Here's my function:

function submit(){ 
    document.optin.action = "link1.php"
    document.optin.target = "_self"; 
    document.optin.submit();
    window.open('http://link2.html','','scrollbars=yes,height=600,width=900,resizable=yes');
    document.optin.action = "link3.php"
    document.optin.target = "_self"; 
    document.optin.submit();
}

The 2nd and 3rd actions work but the first does not. Actions 1 and 3 open on the same window with the latter overrides the former. Any idea what's wrong with my code? pls...

+1  A: 

The first one doesn't work because you're overriding the action with the 3rd one.

I don't know what you want to do, but you can't submit into two targets that are suposed to appear on the same window.

If the first submit is just for data purposes, I would sugest that you do the submit via ajax. so that the 3rd one doesn't overwrite the action.

fmsf
Changing the target of the 1st to _blank does not work either. :(The idea is, the 1st action does the submission of the data to the server so nothing should be displayed about it. While the 3rd displays the page of the next phase of the process.You know what? This code was working until recently. I don't know what went wrong.. :(
Joann
what's going wrong is that you're trying to submit twice and the second submition overwrites the first.If that's really it, then just use ajax for the first submission, it will simplify your life :)
fmsf
I see okay.. I will try that. Thanks :-)
Joann
no problem. and welcome to stackoverflow
fmsf