michaelmcgurk
michaelmcgurk

Reputation: 6509

Display content based on Select Menu dropdown change

I'm currently using the following to display an input field when I change a dropdown menu selection:

<select id="delivery_country" name="d_country" onchange="
 if (this.selectedIndex==14){
  this.form['statesUSA'].style.visibility='visible'
 }else {
  this.form['statesUSA'].style.visibility='hidden'
 };">

However, this only changes the input form element called "statesUSA".

If I want to show the div that this form element is inside, how do I do this?

For the record, my HTML reads:

<div id="usa"> <input type="text" id="statesUSA" /> </div>

Many thanks for any pointers.

Upvotes: 3

Views: 1315

Answers (1)

jackJoe
jackJoe

Reputation: 11148

use document.getElementById(id)

this:

<select id="delivery_country" name="d_country" onchange="if (this.selectedIndex==14){document.getElementById('usa').style.visibility='visible'}else {document.getElementById('usa').style.visibility='hidden'};">

Upvotes: 1

Related Questions