In a page containing a form with select fields, I need to remember the previuos choice (if any) of, for example, the selected state. I want to do it via PHP embedded in JS, where I'm wrong?
<script>
<?php
if(isset( $_GET["state"] )){
$selected_state = $_GET["state"];
?>
$("#state option[<?php echo $selected_state ?>]").attr("selected", "selected");
<?php } ?>
</script>
Thank you in advance!