0

I am going to submit form OnChange but its not working for me. I am using php loop to get values in options under select drop-down.

Here is the code:

   <select id="agnt_name" name="agnt_name" style="font-weight:bold; font-size:13px; height:25px; vertical-align:central;" onchange="this.form.submit()">
    <?php
    $agentname_query = mysql_query("SELECT id, lname, fname FROM `agent` order by fname");
    while($agentname_fetch = mysql_fetch_array($agentname_query)){
    $agentname_id = $agentname_fetch['id'];
    $agentname_fname = $agentname_fetch['fname'];
    $agentname_lname = $agentname_fetch['lname'];
    ?>
    <option <?php if($selected_agent == $agentname_id) { echo 'selected="selected"'; } ?> value="<?php echo $agentname_id;?>" ><?php echo strtoupper($agentname_fname);?> <?php echo strtoupper($agentname_lname);?></option>
    <?php
    }
    ?>
    </select>

if I just submit the form without changing the value in select drop-down its not submitting the form because I did not change the value so I tried to enter one more option like:

<option value="">Select One</option>

It is still not working from my end.. using auto fill for these options jquery is bellow:

<script type="text/javascript" charset="utf-8">
      (function($){
        $(function(){
          $('#agnt_name').selectToAutocomplete();
        });
      })(jQuery);
    </script>

Thanks

Sony G
  • 118
  • 3
  • 11

2 Answers2

1

Is your php code loading the select option properly? Check here onchange this.form.submit() not working for web form

Community
  • 1
  • 1
Abinash Bishoyi
  • 187
  • 1
  • 2
  • 13
0

I have also that trouble time ago.

I've solved with that:

<select onblur="this.form.submit()" onchange="this.form.submit()" name="selectNameForYourPhp">

When the select lost the focus and you not changed the option it will send anyway!

rpasianotto
  • 1,383
  • 1
  • 9
  • 22
  • 1
    Its solved it was about jquery conflict problem I was used multiple jqueries any way its solved thank you so for your answer. – Sony G Jun 24 '13 at 10:58