Modify this js function so that it uses the value fetched from the db instead of the values specified in the array to generate the Select options
<p>How can I modify this function so that it can use the value fetched from the db instead of the values specified in the array used to generate the Select options?</p>

<p>The function allows me to differentiate between the default value of select elements (<em>or 'default state', which are pre-set to the most commonly chosen options)</em>, vs. when a user has actively chosen that value by clicking on the form element <em>(indicating that they made an active decision to leave it set to that value)</em>. The function works correctly in the initial form, and I've posted a fiddle with a working example here: <a href="http://jsfiddle.net/chayacooper/JHAPp/4/" rel="nofollow">http://jsfiddle.net/chayacooper/JHAPp/4/</a></p>

<pre><code>&lt;script&gt;
$('select').focus(function () {
    var option = $(this).find("option[value*=default]");
    option.attr('value', option.attr('value').replace(/_default/g, ''));
});
&lt;/script&gt;
&lt;select name="jeans"&gt;
    &lt;option value="$0"&gt;$0&lt;/option&gt;
    &lt;option value="$50_default" selected="selected"&gt;$50&lt;/option&gt;
    &lt;option value="$100"&gt;$100&lt;/option&gt;
    &lt;option value="$150"&gt;$150&lt;/option&gt;
&lt;/select&gt;
</code></pre>

<p>I'm having trouble adapting the function to work on the account page, where users can review and edit their information. In the initial use of the function I could change the options values manually <em>(i.e. replacing <code>value="$50"</code> with <code>value="$50_default"</code>)</em>, however the account page uses $options array in the printSelectOptions functions below generate the <em></em> element's options in order to pre-select the options matching the db information. The function below pre-selects the values matching the information in the db (regardless of if the user specifically selected the value or if it's still in a 'default state'), however since it needs to remove the '_default' string in order to identify the correct option generated by the <code>$options</code> array it is submitting the value without the '_default' string, regardless of whether or not it's been changed.</p>

<p>How can I modify the js function to work in tandem with this so that if a user hasn't focused on the element it will submit the default value if the value was fetched from the db in the 'default state' (with the '_default' string)?</p>

<pre><code>&lt;?php
    try {  
        $stmt = $conn-&gt;prepare("SELECT * FROM price WHERE user_id = :user_id");  
        $stmt-&gt;bindValue(':user_id', $user_id); 
        $stmt-&gt;execute();
    }  catch(PDOException $e) {echo $e-&gt;getMessage();}
    $row = $stmt-&gt;fetch();
    $search_default = array('_default');
    $replace_default = array('');
    $row_default = str_replace($search_default, $replace_default, $row);

    // This function selects the option matching the value in the db
    function printSelectOptions($dataArray, $currentSelection) {
        foreach ($dataArray as $key =&gt; $value) {
            echo '&lt;option ' . (($key == $currentSelection) ? 'selected="selected"' : '') . ' value="' . $key . '"&gt;' . $value . '&lt;/option&gt;';
        }
    }
?&gt;
&lt;select name="jeans"&gt;
&lt;?php

    // Generates a &lt;select&gt; element with the options specified in this array
    $options = array("Null"=&gt;"", "$0"=&gt;"$0", "$50"=&gt;"$50", "$100"=&gt;"$100", "$150"=&gt;"$150");
    $selected = $row_default['jeans'];

    // Pre-selects the option matching the db information
    echo printSelectOptions($options, $selected); 
?&gt; 
&lt;/select&gt; 
</code></pre>
