newbiephp2020 Posted September 12, 2020 Share Posted September 12, 2020 Hi guys i am a complete novice learning. I want to automatically load a form page without using the submit button. i can get the page to load no problems but the url keeps refreshing in the browser window ? here is the code i am using. <h3>View Mileage.</h3> <form method="post" action="testmileage.php" name="mileage" id = "mileage"> <input type="hidden" name="start-date" value="2020-04-06"> <input type="hidden" name="end-date" value="2021-04-05"> </form> <script>window.onload = function(){ document.mileage.submit(); };</script> Quote Link to comment https://forums.phpfreaks.com/topic/311475-onload-function-repeating/ Share on other sites More sharing options...
gw1500se Posted September 12, 2020 Share Posted September 12, 2020 I'm not following what you want to do. You say you want the page to reload without clicking the submit button. That is what it is doing which makes no sense. There must be some condition, you did not explain, that will cause a reload without the submit button. Quote Link to comment https://forums.phpfreaks.com/topic/311475-onload-function-repeating/#findComment-1581331 Share on other sites More sharing options...
newbiephp2020 Posted September 12, 2020 Author Share Posted September 12, 2020 yes it is working but in my browser window the url is repeating i have screenshot video it. Recording #5.mp4 Quote Link to comment https://forums.phpfreaks.com/topic/311475-onload-function-repeating/#findComment-1581333 Share on other sites More sharing options...
requinix Posted September 12, 2020 Share Posted September 12, 2020 What is the name of the page this form is on? Is the form submitting to itself? Quote Link to comment https://forums.phpfreaks.com/topic/311475-onload-function-repeating/#findComment-1581334 Share on other sites More sharing options...
newbiephp2020 Posted September 12, 2020 Author Share Posted September 12, 2020 here is the full page code <?php session_start(); include('../inc/config.php'); include(ROOT_PATH . 'inc/functions.php'); if (!isset($_SESSION['login'])) { header("Location: " . BASE_URL . "account/login.php"); exit; } if (isset($_SESSION['membership_expired'])) { header("Location: " . BASE_URL . "account/upgradeaccount.php?expired=true"); exit; } $mileage_data = yegetMileageByUserId($_SESSION['login']['id']); include(ROOT_PATH . 'inc/header.php'); ?> <div id="wrapper"> <?php include(ROOT_PATH . 'inc/partials/account-nav.php'); ?> <div id="account-info"> <h3>View Mileage.</h3> <form method="post" action="testmileage.php" name="mileage" id = "mileage"> <input type="hidden" name="start-date" value="2020-04-06"> <input type="hidden" name="end-date" value="2021-04-05"> </form> <script>window.onload = function(){ document.mileage.submit(); };</script> <?php if ($_POST) { ?> <?php $total = 0; ?> <?php foreach($mileage_data as $mileage) { ?> <?php $total += $mileage['mileage_amount']; ?> <?php } ?> <?php if (!empty($total)) { ?> <input type='button' id='print-page' value='Print' onclick='window.print();'> <div id="datatables-wrapper" style="max-height:500px;overflow:scroll;"> <p><?php echo htmlspecialchars($_SESSION['login']['customer_name']); ?></p> <p><?php echo htmlspecialchars($_SESSION['login']['company_name']); ?></p> <p class="total">Total Mileage From Dates Selected:<br> <b><?php echo $total; ?> Miles</b></p> <table class="printable-table"> <thead> <tr> <th>Mileage date</th> <th>Mileage amount</th> </tr> </thead> <tbody> <?php foreach($mileage_data as $mileage) { ?> <tr> <?php $mileage_date = new DateTime($mileage['mileage_date']); ?> <td><?php echo $mileage_date->format('d M Y'); ?></td> <td><?php echo htmlspecialchars($mileage['mileage_amount']); ?></td> </tr> <?php } ?> </tbody> </table> <?php } ?> <?php } ?> </div> </div> </div> <?php include(ROOT_PATH . 'inc/footer.php'); ?> <script language=JavaScript> <!-- //Disable right click script III- By Renigade (renigade@mediaone.net) //For full source code, visit http://www.dynamicdrive.com var message=""; /////////////////////////////////// function clickIE() {if (document.all) {(message);return false;}} function clickNS(e) {if (document.layers||(document.getElementById&&!document.all)) { if (e.which==2||e.which==3) {(message);return false;}}} if (document.layers) {document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;} else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;} document.oncontextmenu=new Function("return false") // --> </script> Quote Link to comment https://forums.phpfreaks.com/topic/311475-onload-function-repeating/#findComment-1581336 Share on other sites More sharing options...
newbiephp2020 Posted September 12, 2020 Author Share Posted September 12, 2020 works ok but url repeating in browser window Quote Link to comment https://forums.phpfreaks.com/topic/311475-onload-function-repeating/#findComment-1581337 Share on other sites More sharing options...
Strider64 Posted September 13, 2020 Share Posted September 13, 2020 (edited) What's the purpose of having a form if there's no submit button? Edited September 13, 2020 by Strider64 Quote Link to comment https://forums.phpfreaks.com/topic/311475-onload-function-repeating/#findComment-1581339 Share on other sites More sharing options...
requinix Posted September 13, 2020 Share Posted September 13, 2020 34 minutes ago, Strider64 said: What's the purpose of having a form if there's no submit button? The whole auto-submit thing doesn't make any sense. Quote Link to comment https://forums.phpfreaks.com/topic/311475-onload-function-repeating/#findComment-1581341 Share on other sites More sharing options...
gw1500se Posted September 13, 2020 Share Posted September 13, 2020 Perhaps the OP is confusing server side (PHP) stateless operation vs client side (javascript) operation. Quote Link to comment https://forums.phpfreaks.com/topic/311475-onload-function-repeating/#findComment-1581344 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.