chrisprse Posted May 16, 2009 Share Posted May 16, 2009 Hello I pass a variable to JavaScript from PHP. Currently this variable is 38. It will increase every time new records are stored in the database. This doesn't work: for(i = 1; i <= num_rows; i++) { $("a#link-" + i).mouseover(function() { $("#tip-" + i).show(); }) $("a#link-" + i).mouseout(function() { $("#tip-" + i).hide(); }) } Whereas this does: $("a#link-1").mouseover(function() { $("#tip-1").show(); $("a#link-1").mouseout(function() { $("#tip-1").hide(); $("a#link-2").mouseover(function() { $("#tip-2").show(); $("a#link-2").mouseout(function() { $("#tip-2").hide(); . . . $("a#link-38").mouseover(function() { $("#tip-38").show(); $("a#link-38").mouseout(function() { $("#tip-38").hide(); Obviously I don't want to edit this file everytime I have a new record in the database! Does anyone have any ideas? Regards Chris Link to comment https://forums.phpfreaks.com/topic/158349-mouseovers-with-for-loops-possible/ Share on other sites More sharing options...
Ken2k7 Posted May 16, 2009 Share Posted May 16, 2009 Verify num_rows is correct. Link to comment https://forums.phpfreaks.com/topic/158349-mouseovers-with-for-loops-possible/#findComment-835267 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.