Knowledge Walls
John Peter
Pune, Maharashtra, India
How to assign dynamic values to textbox using JQuery val() function
13905 Views
Assign value of title attribute of textbox to value attribute. This is taking the title value to value of each textboxes.
HTML
<input type="text" title="Username" /> <br />
<input type="text" title="Password" /> <br />
<input type="text" title="Age" /> <br />
JQuery
//This is the smart way to title attribute value to value of textbox
$("input[type=text]").val(function() {
      return $(this).attr("title");
});

//Otherwise using $.each in Jquery
$.each($("input[type=text]"),function(){
         $(this).val($(this).attr("title"));
         $(this).addClass("font_dimmer");
});
Demo 
Previous Topics
Previous lessons of current book.
Computer software engineer articles of One day One Thing to Know
Best Lessons of "One day One Thing to Know"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details