Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get attr value in jquery

I am trying to get value of attr " _last_val " from my input but unable to produce it.

Below is ? i have tried demo

//below is HTML

<form method="post" action="" id="feedback_form">
  <input type="text" value="2014-08-11" class="date" name="add_by_datetime" _last_val="2014-08-14" >
  <input type="button" name="submit_now" value="Submit" /> 
</form>

// below is script

jQuery(function($) {
   $("form#feedback_form input[name='submit_now']").on("click",function() { 
      var actualadddate  = $("form#feedback_form input[name='add_by_datetime']").attr('_last_val');
      alert(+actualadddate+'aaaaaaaaa');    
   }); 
});

please let me know where i am wrong.

Thanks

like image 862
user3209031 Avatar asked Dec 05 '25 13:12

user3209031


2 Answers

Remove the preceded + from alert and try,

alert(actualadddate + 'aaaaaaaaa');

Live working demo

Note that, in your example you are using .date class to access the attribute if your page has more than 1 element having same class then it will not give you the accurate date. So, be carefull in that case or use unique id to get the attribute.

like image 79
Rohan Kumar Avatar answered Dec 07 '25 04:12

Rohan Kumar


Remove + operator from beginning. Use:

alert(actualadddate+"aaaaaaaaa");

Demo

like image 41
Milind Anantwar Avatar answered Dec 07 '25 02:12

Milind Anantwar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!