2

Here is my Javascript inside of my html file:

<script>
                    $(document).ready(function(){
                        $("#sub").click(function(){
                            var user_issue = $("#issue").val();
                            var user_priority = $("#priority").val();
                            var user_type = $("#type1").val();
                            $.post("BugReport.php",{issue:user_issue,priority:user_priority,type1:user_type},function(data){
                                $("#result").html(data);
                                //location.reload(true);
                            });
                            $.post('BugDisplay.php',{},function(data){
                                $("#BugDisplay").html(data);
                            });
                            document.getElementById('issue').value='';
                            document.getElementById('type1').value='Listing Discrepancy';  //this is my attempt at solving the problem.
                        });
                        $.post('BugDisplay.php',{},function(data){
                                $("#BugDisplay").html(data);
                            });
                    });
                </script>

Here is my html:

<select name = "type1" id = "type1">
                <option value = "Listing Discrepancy">Listing Discrepancy</option>
                <option value = "PO Discrepancy">PO Discrepancy</option>
                <option value = "Pricing Discrepancy">Pricing Discrepancy</option>
                <option value = "Program Glitch">Program Glitch</option>
                <option value = "Receiving Discrepancy">Receiving Discrepancy</option>
                <option value = "RMA Discrepancy">RMA Discrepancy</option>
                <option value = "Sales Discrepancy">Sales Discrepancy</option>
                <option value = "Shipping Discrepancy">Shipping Discrepancy</option>
            </select>

What i want to do is on a click change the select statement so that it resets back to the default display of "Listing Discrepency" and also assign the value to "Listing Discrepency".

3 Answers3

3

You just need to change the selectedIndex property of the select to the first 0 item.

HTML:

<button class="reset">Reset</button>  

jQuery:

$(".reset").click(function () {
    $('#type1').prop('selectedIndex', 0);
});

Or just pure JavaScript:

document.getElementById("type1").selectedIndex = "0";

Working example.

aleksandar
  • 2,399
  • 2
  • 14
  • 22
0

It could be achieved with

$("#type1").val('Listing Discrepancy');

in your onclick event callback

example

andrew
  • 9,313
  • 7
  • 30
  • 61
0

Add this code after select tag

<button onClick="$('#type1').val('Listing Discrepancy');">Reset</button>
waders group
  • 538
  • 3
  • 7