单击“提交”按钮后如何保持选定的下拉值

I want to show selected data after click on submit.I have search too much but not get proper answer.

enter image description here

i used this code but what will be the next step i am not getting this.

if($actiondone!=''){
    echo "<script>
        $('#actiondoc').val();
        </script>";
}

Please guide me for solutuion

Thanks

You cannot use PHP to interact with the user.

After the page has rendered, PHP is finished. If you want to interact with the user (i.e. detect changes to drop-downs, etc) you must use jQuery/javascript only.

For your example, you need to have the jQuery code pre-existing in the page - that is, the javascript gets written into the DOM as the page is being initially rendered. You can add the jQuery/javascript code as part of the HTML, or you can echo that code in PHP as the page is being built -- but it must be on the page when the user gets control of the DOM.

Working demo:

$(function(){
    $('#form_submit').click(function(){
        alert( $('#actiondoc').val() );
        return false; //this line cancels the SUBMIT action of the form
    });
    
    $('#actiondoc').change(function(){
      alert('You chose: ' + $(this).find('option:selected').text() );
    });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<form id="your_form">
    <select id="actiondoc">
        <option value="">Choose:</option>
        <option value="chg">change of tyre</option>
        <option value="rnw">renew tyre</option>
    </select>
    <input id="form_submit" type="submit" value="submit" />
</form>


You say that you want to show the selected choice after user clicks on submit, but there might be a problem with that idea:

When user clicks submit, an HTML form will immediately (a) get the values of the form controls and (b) deliver them to the page specified on the <form action="new_page.php" method="post"> -- so, in this code right here, the browser will navigate over to new_page.php and deliver the form values to that page.

The point is: the page will change (unless you are using AJAX - are you?) - so you cannot show anything more on that page because the user isn't on that page any longer.

So, you can show the value of the #actiondoc control on the new page, OR you can intercept the submit function, as I did in my demo above when I displayed the alert()

If you tell us more about exactly what you want to do, we can help more.


References:

https://www.w3schools.com/xml/ajax_intro.asp

AJAX vs Form Submission

YouTube - Simple AJAX Contact Form - HTML, PHP, AJAX

</div>