Auto-submit form with PHP action via JavaScript -


forgive me if question naive. i'm new javascript , learning way through setbacks form i'm using display data.

an icao code passed #depicao <select> menu via $_get['icao'] in javascript code @ bottom of script. on page load, <select> menu populated $_get['icao'] value.

after #depicao <select> menu populated, i'd form automatically submit with populated value. train of thought if include

document.getelementbyid("form").submit(); 

as last line in script, can script submit after loads $_get['icao'] value. unfortunately, hasn't been working, however.

notice: code contains multiple <input type="submit" name="submit"> buttons. believe culprit.

see code below.

<form id="form" action="<?php echo actionurl('/schedules/view');?>" method="post"> <div id="tabcontainer">     <ul>         <li><a href="#depapttab" onclick="formreset()"><span>via departure airport</span></a></li>         <li><a href="#arrapttab" onclick="formreset()"><span>via arrival airport</span></a></li>     </ul>     <div id="depapttab">         <select id="depicao" name="depicao">         <option value="">select all</option>         <?php         $exclude = array(13, 18, 19, 22); // airport ids found in phpvms_airports not included in dropdown menu         if(!$depairports) $depairports = array();             foreach($depairports $airport) {                 if(!in_array($airport->id, $exclude)) { // exclude values in above array dropdown menu                     echo '<option value="'.$airport->icao.'">'.$airport->icao.' - '.$airport->name.'</option>';                 }             }         ?>         </select>         <input type="submit" name="submit" value="find flights" />     </div>     <div id="arrapttab">         <select id="arricao" name="arricao">             <option value="">select all</option>         <?php         $exclude = array(13, 18, 19, 22); // airport ids found in phpvms_airports not included in dropdown menu         if(!$depairports) $depairports = array();             foreach($depairports $airport) {                 if(!in_array($airport->id, $exclude)) { // exclude values in above array dropdown menu                     echo '<option value="'.$airport->icao.'">'.$airport->icao.' - '.$airport->name.'</option>';                 }             }         ?>         </select>         <input type="submit" name="submit" value="find flights" />     </div> </div> <input type="hidden" name="action" value="findflight" /> </form> <script type="text/javascript"> function formreset() {     document.getelementbyid("form").reset(); } function setselectedindex(s, valsearch) {     // loop through items in drop down list     (i = 0; i< s.options.length; i++) {          if (s.options[i].value == valsearch) {             // item found. set property , exit             s.options[i].selected = true;             break;         }     }     return; } setselectedindex(document.getelementbyid("depicao"),"<?php if(isset($_get['icao'])) { echo $_get['icao']; } else { echo 'select all'; } ?>"); document.getelementbyid("form").submit(); </script> 

form auto submission confusion ?:

after #depicao menu populated, i'd form automatically submit itself populated value.

how understood you want form submitted automatically when select menu populated ? think meant when user chooses selection, should submit automatically. if mean. please add onchange="//submitfunction()" onto <select> tag


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -