Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

PHP / Javascript Form Drop-Down index?

I have an HTML form that passes data to another PHP page via the "POST" method.

I have a "SELECT" drop-down list in the form....and I am getting the value data from the OPTIONS...however I wanted to know if there was a way to also pass the "list index" as data

I want to be able to know if the user has changed from the intial value presented in the drop-down box.

1 Answer

Relevance
  • 1 decade ago
    Favorite Answer

    A trivial solution would be to add a hidden field and pass the selected index in that.

    <html>

    <head>

    <!--

    No matter which you select

    as "best answer" - pick one.

    -->

    <script>

    function submitForm0(bRef) {

    var form = bRef.parentNode;

    var sel = bRef.parentNode.f0sel;

    var idx = sel.selectedIndex;

    form.selIdx0.value = idx;

    // form.submit();

    alert(form.selIdx0.value);

    }

    </script>

    </head>

    <body>

    <form>

    <select name="f0sel">

    <option>f0selopt0</option>

    <option>f0selopt1</option>

    <option>f0selopt2</option>

    </select>

    <input type="button"

    value="submit form0"

    onclick="submitForm0(this)" />

    <input type="hidden" name="selIdx0" />

    </form>

    </body>

    </html>

Still have questions? Get your answers by asking now.