javascript - Click link and Insert text from hidden field into input field, more than 1 time and replace the text in the input field -


click link , insert text hidden field input field, more 1 time , replace text in input field.

now code can insert text when input field empty, want replace text if click "testname" button

anyone can me? doesn't matter if javascript/jquery

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>     <script type="text/javascript">  function setsearch(val, search) {  $('input[id ^="searchform"]').each(function (index) {   var s = "searchform" + search;   if ($(this).attr("id") == s) {     $(this).attr("value", val);     return false;   } }); } </script> <a href="javascript:setsearch ( $('#name').attr('value'), 'name' );"> testname </a>  <input id="name" name="name" type="hidden" value="testname" /> name <input name="name" type="text" id="searchformname" value=""  /> 

my fiddle http://jsfiddle.net/ftpwf/2/

use .val(val) instead of .attr("value", val);


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

delphi - Indy UDP Read Contents of Adata -