not getting the right index value

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

not getting the right index value

Post 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
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: not getting the right index value

Post 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?
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

Re: not getting the right index value

Post 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 :)
Post Reply