0

My select is giving me undefined for is index.

My code:

HTML

<div name="daysToReorder" class="days_to_reorder" onchange="getReOrderTables(this)"> Day to reorder <br>
              <select name="daysToReorder">
              <option value="A">A</option>
              <option value="B">B</option>
              <option value="C">C</option>
              <option value="D">D</option>
              <option value="E">E</option>
              <option value="F">F</option>
              </select></div>

JS

  function getReOrderTables(select)
    {

    alert(select.selectedIndex);


    }
1
  • 2
    this is the <div/>, not the <select/>(div's doesn't have a selectedIndex-property) Commented Mar 10, 2014 at 20:51

1 Answer 1

3

Since the onchange is on the <div>, this refers to the <div>. <div>s don't have a selectedIndex.

Try applying the event to the <select> instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.