Bhargav Chudasama
Bhargav Chudasama

Reputation: 408

get a textbox value which will keyup event rise html

<html>
<?php  for($i=1;$i<5;$i++){?>
    <input type="text" value="<?php echo $i; ?>" id="val".$i>
<?php } ?>
</html>
<script src="../jquery-3.1.1.js"></script>
<script>
    $("input").keyup(function()
    {
        alert($("#val").val());
    });
</script>

NOTE I will try to get text-box value when key-up event fire but always first text box value display how i will get text-box value which key-up event fire

Upvotes: 0

Views: 578

Answers (2)

Calos
Calos

Reputation: 1942

Use this

$("input").keyup(function()
{
    alert($(this).val());
})

By the way, the id attribute must be unique within the HTML document, see http://www.w3schools.com/tags/att_global_id.asp

Upvotes: 2

mith
mith

Reputation: 1700

use alert($(this).val()); instead of alert($("#val").val());

Upvotes: 0

Related Questions