I have a form inside a while loop in PHP. There is action="javascript:block_grade($id)", but when i alert(id) or alert(lvl) in the block_grade function, I receive the same numbers from all the the loops?
This is inside my loop:
echo '<form action="javascript:block_grade('.$show['id'].')" method="post">';
echo 'Change blockgrade: ';
echo '<input type="text" name="lvl" size="1" value="'.$show['lvl'].'">';
echo '<input type="submit" value="Save">';
echo '</form>';
This is my function at bottom:
<script>
function block_grade ( id ) {
var lvl = $('input[name=lvl]').val();
alert(lvl);
alert(id);
}
</script>
How can I solve this, and is there any more effective way than this, maybe?