Page 1 of 1

not getting the right index value

Posted: Mon Aug 11, 2008 11:58 am
by bouncer
hi there,

i'm here with a little issue, that i can't solve :(,

Code: Select all

 
echo "<td><select id=\"message\" onChange=\"alert(this.value)\">"; // here i can get the right value everytime that i change it
while( $row1 = mysql_fetch_array($result1, MYSQL_ASSOC) ) {
    echo "<option value=\"".$row1['id_message']."\">".$row1['id_message'] . "-" . $row1['desc']."</option>";
}
echo "</select></td>";
 
now on the javascript, i try to get the right value but it always return the first index.

Code: Select all

 
var index = document.getElementById("message").selectedIndex;
alert(document.getElementById("message").options[index].value);
 
can someone help me solving this issue ?

thanks in advance

Re: not getting the right index value

Posted: Mon Aug 11, 2008 4:20 pm
by kaszu
I added that JS on link click and it works for me on FF3, IE6, IE7, Safari and probably will on other browsers too.
When are your JS executed?

Re: not getting the right index value

Posted: Tue Aug 12, 2008 5:30 am
by bouncer
kaszu wrote:I added that JS on link click and it works for me on FF3, IE6, IE7, Safari and probably will on other browsers too.
When are your JS executed?
i've managed to figured out my problem, i have this code inside a loop so i forget about give a different name to all the selects, so when i clicked in the button he returned the value of the first select only, that was the same to all the others. :roll:

thanks anyway :)