As a newbie I am trying to run a PHP file and then an HTML file automatically using an
onload="Trigger();"
in the body of the HTML.
Enclosed is my code but it will not work even though the onload
is accessing the Javascript code.
<html> <head> <meta http-equiv="Content-Language" content="en-ca"> <meta name="GENERATOR" content="Microsoft FrontPage 5.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <script src="jquery.js" language="javascript1.2" type="text/javascript"></script> <script src="swapstyle.js" language="javascript1.2" type="text/javascript"></script> <script src="cookie.js" language="javascript1.2" type="text/javascript"></script> <script language="Javascript"> function Trigger() { document.Trigger.action = "http://www.Website.com/ISP.php"; document.Trigger.target = "_top"; document.Trigger.submit(); document.Trigger.action = "http://www.Website.com/Home.html"; document.Trigger.target = "_top"; document.Trigger.submit(); return true; } </script> </head> <body onload="Trigger();"></body> </html>
Any suggestions?
Advertisement
Answer
It looks like you need to submit two forms onLoad. In your HTML create two forms, but the issue is that you are targeting the same frame, so while one is submitting the other is trying to as well (you could time it so one submits, the other waits until it is submitted OR target another frame like so:
<body onload="trigger();"> <form name="php-form" action="http://www.Website.com/ISP.php" target="_top"> <form name="htm-form" action="http://www.Website.com/Home.html" target="_another"> </body>
Then:
function trigger(){ document.php-form.submit(); document.htm-form.submit(); }
OR a timed method so one submits then the other shortly after using the same target:
<body onload="trigger();"> <form name="php-form" action="http://www.Website.com/ISP.php" target="_top"> <form name="htm-form" action="http://www.Website.com/Home.html" target="_top"> </body> function trigger(){ document.php-form.submit(); setTimeout(function(){ document.htm-form.submit(); }, 2000); // 2 seconds after }
Hopefully this helps.