1

I have looked and tried several methods from the link below but my selection continually does not submit onchange.

Javascript select onchange='this.form.submit()'

My source can be see here:

http://xeroharm.com.au/settings/users/test.html

The code below I have used works in some places throughout my site but not others. I have copied the source code and made a test so you can see something that might be preventing this from submitting on change.

the select code is like so:

<select id="mytrigger" name="EmployeeChange" data-placeholder="Change Employee..." class="chosen-select"  tabindex="2" onchange="myFunction()">
    <option value=""></option>
    <?php 
        $result = mysqli_query($conn,"SELECT * FROM Employee ORDER BY FirstName;");

        while($row = mysqli_fetch_array($result)){
            echo "<option value='".$row['Employee_ID']."'>".$row['FirstName']." ".$row['LastName']."</option>";
        }
    ?>
</select>

Any assistance would be greatly appreciated.

Community
  • 1
  • 1
owen
  • 137
  • 2
  • 13
  • Please see [*How to create a ninimal, complete and verifiable example*](http://stackoverflow.com/help/mcve). – RobG Apr 08 '16 at 02:12
  • Note that `onchange='this.form.submit()'` on a select element will create an inaccessible interface, since it the user attempts to use the keyboard for in–page navigation and uses the cursor keys to change options, some browsers submit a change event every time the option is changed whether that's the one the user wanted or not. – RobG Apr 08 '16 at 03:03
  • Can you show us the client side result of the PHP? – Dominique Fortin Apr 08 '16 at 03:07

1 Answers1

1

There are script errors and syntax errors on your page. In JavaScript, any error will prevent scripts from running altogether, which is why the on change event isn't being triggered.

Fixing the errors should resolve the issue. It looks like the first ones are due to a missing jQuery dependency.

[Error] ReferenceError: Can't find variable: $
    global code (test.html:42)
    global code (test.html:42)
[Error] ReferenceError: Can't find variable: $
    global code (test.html:326)
    global code (test.html:42)
[Error] SyntaxError: Unexpected token '<'
    (anonymous function) (login:1)
Mark
  • 559
  • 3
  • 11
  • It's PHP code. It's not meant to be seen on client side or be executed by the browser for that matter. – Dominique Fortin Apr 08 '16 at 03:06
  • I changed the order of the javascript and it worked. but other elements on throughout site got broken. I'm going to have to rethink how i structure the javascript for the site. – owen Apr 08 '16 at 04:18