# Javascript: reveal State/Province dropdown on selection of US or Canada

**URL:** https://forum.kirupa.com/t/javascript-reveal-state-province-dropdown-on-selection-of-us-or-canada/326032
**Category:** web dev
**Created:** [November 19, 2011, 12:30am UTC](https://forum.kirupa.com/t/javascript-reveal-state-province-dropdown-on-selection-of-us-or-canada/326032 "2011-11-19T00:30:22Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Pherank](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@Pherank](https://forum.kirupa.com/u/Pherank)
#### Post date: [November 19, 2011, 12:30am UTC](https://forum.kirupa.com/t/javascript-reveal-state-province-dropdown-on-selection-of-us-or-canada/326032/1 "2011-11-19T00:30:22Z")

</div>

I’m not sure how to ask for the selected value from a pulldown menu. This is what I have so far:

```auto

In the HTML header:

<script language="JavaScript" type='text/javascript'>
function selectCountry(elem){
    if(elem.value == "United States" || elem.value == "Canada"){
        document.getElementById('div-state').style.display = '';
        document.getElementById('div-state').style.visibility = '';
        return false;
    }else{
        return true;
    }
}
</script>

In the form:

<div class="optionalField" id="div-state" style="display:none;visibility:hidden;">
      <label for="state">State/Province:</label>
      <select tabindex="6" name="state" id="state" class="selectOne">
        <option value="">Select a State/Province</option>
        <option value="">---------------</option>
        <option value="AL">AL - Alabama</option>
      </select>
</div>

      <select tabindex="8" name="country" id="country" class="selectOne required" onselect="selectCountry(document.getElementById('country');">
        <option value="">Select a Country</option>
        <option value="">---------------</option>
        <option value="United States">US - United States</option>
        <option value="Canada">CA - Canada</option>
        <option value="">---------------</option>
        <option value="Afghanistan">AF - Afghanistan</option>
      </select>

```

I think I’m trying to get to this value:  
e.options[e.selectedIndex].value  
but I’m unsure of how to express it.
