php - javascript function inside loop not working -
i displaying online users. when click 1 of user, corresponding user should displayed in text box below. using javascript this, taking first user. when click second user, first user displayed in below text box. why taking first array?
<?php foreach($query $row) { ?> <input type="text" name="user" id="user" value="<?php echo $row->users;?> onclick="select_online()"> <?php } ?> <script> function select_online() { var user=document.getelementbyid("user").value; document.getelementbyid("usersonline").value=user; } </script> name:<input type="text" name="usersonline" id="usersonline">
first of all, using same id many elements mistake. should make diverse id
attribute generated inputs.
second, should use this
value of current element:
function select_online() { var user=this.value; document.getelementbyid("usersonline").value=user; }
document.getelementbyid("user")
statement select element id
attribute equal "user" , same. probably, not want. if understood correctly, want value
of clicked element, mentioned before, can achieve using this
expression, points clicked element.
Comments
Post a Comment