Below is how I made an alert showing the "dynamic" id using onblur. I have a while loop with input fields so the id is pulling from a unique id in a database.
How would I get the value too? Normally I would just set a variable like usual but it's in a loop so I'm not understanding how.
<script type="text/javascript">
function doUpdateEntries(clicked_id) {
alert(clicked_id);
// how do I get the value AND id?
}
</script>
while ($row = mysql_fetch_assoc($result)) {
<input onblur="doUpdateEntries(this.id);" id=".$row['entry_id']." name=".$row['entry_id']." type="text" value=".$row['reviews'].">
}
Below is how I made an alert showing the "dynamic" id using onblur. I have a while loop with input fields so the id is pulling from a unique id in a database.
How would I get the value too? Normally I would just set a variable like usual but it's in a loop so I'm not understanding how.
<script type="text/javascript">
function doUpdateEntries(clicked_id) {
alert(clicked_id);
// how do I get the value AND id?
}
</script>
while ($row = mysql_fetch_assoc($result)) {
<input onblur="doUpdateEntries(this.id);" id=".$row['entry_id']." name=".$row['entry_id']." type="text" value=".$row['reviews'].">
}
Share
Improve this question
edited Feb 26, 2013 at 3:03
Ry-♦
225k56 gold badges492 silver badges498 bronze badges
asked Feb 26, 2013 at 2:48
LITguyLITguy
6334 gold badges15 silver badges40 bronze badges
4
- 3 instead of doUpdateEntries(this.id) you can use doUpdateEntries(this), clicked_id.value will give you its value and clicked_id.id will give you its id. – Ankit Jaiswal Commented Feb 26, 2013 at 2:57
- hey that's perfect! I would love to give you credit for the answer. For now i'll just upvote your ment. – LITguy Commented Feb 26, 2013 at 2:58
-
onblur="doUpdateEntries(this.id, this.value);"
? Or even better just pass the whole event target to the function. – Bergi Commented Feb 26, 2013 at 2:58 - @LITguy I feel this does not fit as an answer, I am glad it helped you :) – Ankit Jaiswal Commented Feb 26, 2013 at 3:01
2 Answers
Reset to default 2You could simply pass through the value to the function doUpdateEntries
as another parameter.
<script type="text/javascript">
function doUpdateEntries(id, value) {
alert(id);
alert(value);
}
</script>
while ($row = mysql_fetch_assoc($result)) {
<input onblur="doUpdateEntries(this.id, this.value);" id=".$row['entry_id']." name=".$row['entry_id']." type="text" value=".$row['reviews'].">
}
As Ankit mentions… just pass in this
, à la
<input onblur="doUpdateEntries(this);" id=".$row['entry_id']." name=".$row['entry_id']." type="text" value=".$row['reviews'].">
Below is how I made an alert showing the "dynamic" id using onblur
. I have a while
loop with input fields so the id
is pulling from a unique id in a database.
How would I get the value too? Normally I would just set a variable like usual but it's in a loop so I'm not understanding how.
function doUpdateEntries(_this) {
var _id = _this.id;
var _name = _this.value;
}