Check radio button if
<p>I want to select a radio button depending on an input field. This seems very simple but its not working. Basically a user fills out a form and depending on the state input field, it picks the state tax radio button. </p>

<p>The code below is not firing for some reason, any idea's?</p>

<p>The input field</p>

<pre><code>&lt;div class="form-group"&gt;
 &lt;label for="state" class="col-sm-3 control-label"&gt;State&lt;/label&gt;
  &lt;div class="col-sm-9"&gt;
    &lt;input type="text" class="form-control" id="state" name="state" placeholder="State" onblur="picktax();" required /&gt;
  &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>The radio button</p>

<pre><code>&lt;div class="form-group"&gt;
&lt;label for="emailaddress" class="col-sm-3 control-label"&gt;Tax&lt;/label&gt;
&lt;div class="col-sm-9"&gt;
    &lt;br&gt;
    &lt;div class="col-sm-9"&gt;
        &lt;label class="checkbox-inline"&gt;
            &lt;input type="radio" class="px" name="tax2" id="radio1" class="radio" value="0" / /&gt;
            &lt;span class="lbl"&gt;Tax Exempt&lt;/span&gt;
        &lt;/label&gt;
        &lt;br&gt;
    &lt;/div&gt;
    &lt;div class="col-sm-9"&gt;
        &lt;label class="checkbox-inline"&gt;
            &lt;input type="radio" class="px" name="tax2" id="radio2" class="radio" value="0.0875" /&gt;
            &lt;span class="lbl"&gt;NYC 8.875%&lt;/span&gt;
        &lt;/label&gt;
        &lt;br&gt;
    &lt;/div&gt;
    &lt;div class="col-sm-9"&gt;
        &lt;label class="checkbox-inline"&gt;
            &lt;input type="radio" class="px" name="tax2" id="radio3" class="radio" value="0.08625" /&gt;
            &lt;span class="lbl"&gt;LI 8.625%&lt;/span&gt;
        &lt;/label&gt;
        &lt;br&gt;
    &lt;/div&gt;
    &lt;div class="col-sm-9"&gt;
        &lt;label class="checkbox-inline"&gt;
            &lt;input type="radio" class="px" name="tax2" id="radio4" class="radio" value="0.07" /&gt;
            &lt;span class="lbl"&gt;NJ 7%&lt;/span&gt;
        &lt;/label&gt;
        &lt;br&gt;
    &lt;/div&gt;
    &lt;div class="col-sm-9"&gt;
        &lt;label class="checkbox-inline"&gt;
            &lt;input type="radio" class="px" name="tax2" id="radio5" class="radio" value="0.06" /&gt;
            &lt;span class="lbl"&gt;Philly 6%&lt;/span&gt;
        &lt;/label&gt;
        &lt;br&gt;
    &lt;/div&gt;
    &lt;div class="col-sm-9"&gt;
        &lt;label class="checkbox-inline"&gt;
            &lt;input type="radio" class="px" name="tax2" id="radio6" class="radio" value="0.0635" /&gt;
            &lt;span class="lbl"&gt;CT 6.35%&lt;/span&gt;
        &lt;/label&gt;
        &lt;br&gt;
    &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>The script</p>

<pre><code>&lt;script&gt;
function picktax() {

var statevalue = document.getElementById('state').value;
var nyvalue = "NY";
var livalue = "LI";
var njvalue = "NJ";

if (statevalue == nyvalue) {

$("#radio2").prop("checked", true)

} elseif (statevalue == livalue) {

$("#radio3").prop("checked", true)

} elseif (statevalue == njvalue) {

$("#radio4").prop("checked", true)


} else {

 alert("test");
}

}
&lt;/script&gt;
</code></pre>

<p>updated, still not firing</p>