Getting undefined with the below code..

Getting undefined with the below code..

Hi,

This is my code, I am trying to get the attribute of previous td child from current td input, kindly see the below and suggest me the solution.

HTML
  1. <html>
  2. <head><title>I am a beginner</title></head>
  3. <body>
  4. <table><thead/><tbody>
  5. <td><input name="1sttextbox" type="text" value="10/22/2015" id="1"/></td>
  6. <td><input name="2ndtextbox" type="text" value="10/23/2015" id="2"/></td>
  7. <td><input name="3rdtextbox" type="text" value="10/21/2015" id="3"/></td>
  8. </tr></tbody>
  9. </table>
  10. </body>
  11. </html>

Jquery

  1. $(function() {
  2. var input=$("input[type='text']");
  3. input.blur(function() {
  4.     var val1=$(this).val();
  5.     var val2 = $(this).closest('td').prev('td input').attr('value');
  6.     alert(val1);
  7.     alert(val2);
  8.     return false;
  9. });

I am getting the val1 in alert box but in undefined for val2. Please check and suggest solution.