Fenhopi Posted July 19, 2011 Share Posted July 19, 2011 Hi, I'm aware that there are some difficulties with using javascript in php loops because of the client side and server side work that's being done. Anyways, here's what I got: function alertBox() { document.sendform.to2.value = document.getElementById('test3').value; document.sendform.to.value = document.getElementById('test4').value; e.style.display="none"; } while ($row = mysql_fetch_array($getRecord)) { $TheirProfilePicture = $row['profilepicture']; $mysock = getimagesize("http://face2blog.comlu.com/images/uploads/$TheirProfilePicture?time=time()");?> <li><a href="#" onClick="alertBox();" id="test"><img src="http://face2blog.comlu.com/images/uploads/<? echo $TheirProfilePicture ?>?time=<?php echo time(); ?>" <? echo imageResize($mysock[0], $mysock[1], 45); ?> /> <font color="grey" size="3"><?php echo $row['firstname']; ?> <?php echo $row['lastname']; ?></font><input type="hidden" id="test3" value="<?php echo $row['firstname']; ?> <?php echo $row['lastname']; ?>"><input type="hidden" id="test4" value="<?php echo $row['username']; ?>"></a></li> <?php } Please ignore the lach of script tags, I'm just pasting in what's relevant. This is the code of my autosuggest search thingy. When a user clicks one of the suggestions I'd like alertbox(); to get the info of the one I picked, not the last result that was looped. Is there a way or a trick that I could do to make this work? Thank you in advance! Quote Link to comment https://forums.phpfreaks.com/topic/242329-troubles-with-a-javascript-function-inside-a-php-loop/ Share on other sites More sharing options...
AyKay47 Posted July 19, 2011 Share Posted July 19, 2011 I would recommend using AJAX here https://developer.mozilla.org/en/AJAX Quote Link to comment https://forums.phpfreaks.com/topic/242329-troubles-with-a-javascript-function-inside-a-php-loop/#findComment-1244612 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.