StuBlackett
StuBlackett

Reputation: 3857

Only load when its reached

I am creating a 3D Secure form, which if the user is required to re-directs them to the 3D Secure Banks' gateway.

The issue I have is that the following script :

<SCRIPT LANGUAGE='Javascript' >
<!--
function OnLoadEvent()
{
document.mainform.submit();
}
//-->
</SCRIPT>

Appears to need to be loaded on bodyOnload="OnloadEvent"

Unfortunately I can't modify the body tags of the page. So I need the code to load when its called in context of the PHP Script.

The code for that is:

} else if($result_arr['valid'] == 'true' && ($mpistatus == '200')) {
          
          $threedurl = urldecode($result_arr['acs_url']);
          $paymentauth = $result_arr['PaReq'];
          $mdcode = $result_arr['MD'];
           
            echo 
            "<form name='mainform' action='$threedurl' method='POST'>
                <center>
                    <h1>Processing your 3D Secure Transaction</h1>
                    <h3>Please click Submit to continue
                    the processing of your 3D Secure
                    transaction.</h3>
                    <input type='submit' value='Submit'>
                </center>
                <input type='hidden' name='PaReq' value='$paymentauth'>
                <input type='hidden' name='TermUrl' value=''>
                <input type='hidden' name='MD' value='$mdcode'>
            </form>
            <SCRIPT LANGUAGE='Javascript' >
            <!--
            function OnLoadEvent()
            {
            document.mainform.submit();
            }
            //-->
            </SCRIPT>
            ";
      }

Can I get it to load the form only when called within the script, if so, how?

Upvotes: 0

Views: 121

Answers (2)

Manse
Manse

Reputation: 38147

Just add it to the onload method of the window ?

if (window.addEventListener) // W3C standard
{
  window.addEventListener('load', myFunction, false); // NB **not** 'onload'
} 
else if (window.attachEvent) // Microsoft
{
  window.attachEvent('onload', myFunction);
}

Upvotes: 1

solendil
solendil

Reputation: 8468

Sure ! Just remove the surrounding function def, and the code will be executed right away:

<SCRIPT LANGUAGE='Javascript' >
<!--
document.mainform.submit();
//-->
</SCRIPT>

Upvotes: 1

Related Questions