How do I retrieve values from combos dynamically added to html table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Corwin Moyne
    New Member
    • Feb 2012
    • 37

    #1

    How do I retrieve values from combos dynamically added to html table

    I have a table with 10 rows added by looping throw a $result from a database query. When the user selects an option from one of the combos, how do I get its value. I have used Javascript but I can only get it to work with the first combo.

    COMBO CODE
    Code:
    echo"<td><select name='status[]' id='combo' onchange='getComboValue()'>";
    		echo"<option value='' ". (($row['finished']) == 0 ? "selected='selected'":"") . " >Fixture</option>";
    		echo"<option value='' ". (($row['finished']) == 1 ? "selected='selected'":"") . " >Live</option>";
    		echo"<option value='' ". (($row['finished']) == 2 ? "selected='selected'":"") . " >Result</option>";
    		echo"</select></td>";
    JAVASCRIPT
    Code:
    function getComboValue()
    {
    	var combo = document.getElementById("combo");
    	var selectedText = combo.options[combo.selectedIndex].text;
    	document.getElementById("hiddenStatus").value = selectedText;	
    }
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You said you got it to work with the first combo. Implying that there was at least one other combo. But your code only shows one combo. And it's the combo that works. So I don't know what your question is.

    Comment

    Working...