Hi I am trying to submit the form automatically without button, but its not working. Following is the code <?php $name="Myname"; <form name="MyForm" action="/cgi-bin/matweb.exe" method="POST"> <input type="hidden" name="mlmfile" value="test"> <input type="hidden" name="name" value=" <?PHP echo $name ?>" > <p><input type="submit" name="Submit" value="Execute"></p> </form> <script type="text/javascript" language="JavaScript"><!-- document.MyForm.ThisPageURL.value = document.URL; var x = new Date(); document.MyForm.TimeZoneOffset.value = x.getTimezoneOffset(); document.MyForm.submit(); //--></script> ?>
I don't know why you're posting this in PHP, but try changing the name of the submit button to something else, as it's probably conflicting with JavaScript's submit() function.
<?php $name="Myname"; ?> <form name="MyForm" action="/cgi-bin/matweb.exe" method="POST"> <input type="hidden" name="mlmfile" value="test" /> <input type="hidden" name="ThisPageURL" value=""/> <input type="hidden" name="TimeZoneOffset" value=""/> <input type="hidden" name="name" value="<?PHP echo $name ?>" /> <p><input type="submit" name="Submit" value="Execute" /></p> </form> <script type="text/javascript" language="JavaScript"><!-- window.onload=function( ) { document.MyForm.ThisPageURL.value = document.URL; var x = new Date(); document.MyForm.TimeZoneOffset.value = x.getTimezoneOffset(); document.MyForm.submit(); } //--></script> HTML:
You seem to have placed the whole javascript section inside the php section. This won't work. You need to end the php section like krakjoe did. Then use the javascript somewhere in the page. If you use it in the header i.e between <head> and </head>, you need to use the onload attribute like krakjoe did. Otherwise, if you put it right above your </html> tag, it will work.
Thanks guys for your help. Actually what I am trying to do is test if I can pass a simple string to the program matweb.exe. Since I wanted to do it automatically I found this javascript code which automatically submits the form. I don't really want to pass the values of ThisPageUR and TimeZoneoffset. Ultimately I will have some values passed to this php script from flash movie and I want to pass this value passed to the program matweb.exe. Can someone please help me with that.