1

I have a table as below;

<table id="mytable" cellpadding="0" cellspacing="0">
<tr>
<td>&nbsp;</td>
<td><input type="text" name="qwer"></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="text" name="asddf"></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="text" name="zxcv"></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="text" name="poiu"></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="text" name="lkjh"></td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="3"> <button id="BUT">BUT</button> </td>
</tr>
</table>

The middle cells contain text fields with names. I want to get data (I think .val()) from specific input fields. How can I get them? Say I want to alert value we enter in input name="zxcv".

You can see my Fiddle here.

How can I do this?

0

2 Answers 2

3

try this

$('#mytable input[name=zxcv]').val()
Sign up to request clarification or add additional context in comments.

Comments

0

If you want to iterate on input fields, and show "name" and "value" when "BUT" is clicked :

$("#BUT").click(function() {
    $("#mytable input").each(function() {
        alert("name : " + $(this).attr('name') + " - value : " + $(this).val());
    });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.