Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
1.67/5 (2 votes)
See more:
I want ways to automatically execute the "Submit" button like ajax.
"Window.onload" is not working.

PHP
         <?php
	$mo = filter_input(INPUT_POST, "mo1");
	$dy = filter_input(INPUT_POST, "dy1");
	$yr = filter_input(INPUT_POST, "yr1");
	$tz = filter_input(INPUT_POST, "tz1");
	$dst = filter_input(INPUT_POST, "dst1");
	$hr = filter_input(INPUT_POST, "hr1");
	$mn = filter_input(INPUT_POST, "mn1");
	$sc = filter_input(INPUT_POST, "sc1");
	$ampm = filter_input(INPUT_POST, "ampm1");
	
	if ($ampm == "AM" and  $hr == "12"){
	            $hr=0;
	    } elseif ($ampm == "PM" and $hr < "12"){
	            $hr = $hr + "12";
	    }
	    $jd0 = 367 * $yr - floor(7 * ($yr +  floor(($mo + 9) / 12)) / 4) +  floor(275 * $mo / 9) + $dy + 1721013.5;
	    $jd = $jd0 + ($hr - $tz - $dst + $mn / 60 + $sc / 3600) / 24;
	    $k = ($jd - 2451550.09765) / 29.530588853;
	    $kDec = ($k - floor($k));
        }
?>

        <form id="myform" action="../php/e-Moon_Phase.php" method="post">
		<input name="jd2" type="hidden" value="<?php echo $jd; ?>" />
		<input name="k2" type="hidden" value="<?php echo $k; ?>" />
		<input name="kDec2" type="hidden" value="<?php echo $kDec; ?>" />
		<input name="Submit1" type="submit" value="submit" />
	</form>
	<script type="text/javascript">
            window.onload = function () {
        	document.myform.Submit1.click();
            }
        </script>
Posted
Updated 30-May-14 6:41am
v3

1 solution

Better use the universal approach: define some function. Call it in two (or more) places: one from the button click handler, another from where you want to have to same effect as the click. Isn't that simple?

—SA
 
Share this answer
 
Comments
Teledextri 30-May-14 13:03pm    
Could you give examples on how to call a php function from a button click handler.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900