Hello. I have two input, the first name and the second keywords . The keywords input has a default value and a certain placeholder value. It looks like this:

 <input type="text" name="name" /> <input type="text" name="keywords" value="Купить {name}, цены на {name} /> 

The question is, is it possible to automatically take a value from the name field and substitute the keywords field in {name} ? I think maybe something like putting a variable in value in which it wakes up a value from the name field, but I don’t even know how. Tell me please.

    1 answer 1

    You can put an event handler in the name field. In the example, if you change the value in the name field, the value of the keywords field will be updated.

     var ctKeywords = $('input[name="keywords"]'); $('input[name="name"]').keyup(function(e) { var name = $(this).val() || '(наименование не указано)'; $(ctKeywords).val('Купить ' + name + ', цены на ' + name); }); 
     input { display: block; width: 500px; margin-bottom: 10px; } 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" name="name" /> <input type="text" name="keywords" value="Купить (наименование не указано), цены на (наименование не указано)" />