user3193610
user3193610

Reputation: 95

jquery change placehoder input from dropdown

I have a problem, I want a command in the dropdown that I created. dropdown and input code example:

<select name="field" id="list_field">
                  <option value='all'>All Field</option>
                  <option value="A" >AAA</option>
                  <option value="B" >BBB</option>
</select>
<input type="text" name="keyword" placeholder="add text in here..">

if I want a select dropdown selected, then the placeholder in the textbox also changes. is a case in point: If I select the dropdown "A", the placeholder will be changed to "AAAxxxx". how jquery or javascript code to perform these commands? is there anything that can help me?

Upvotes: 0

Views: 128

Answers (2)

brunozrk
brunozrk

Reputation: 783

$(function() {
  $("#list_field").change(function(){
    if ($(this).val() == 'A'){
        $("input[name=keyword]").attr('placeholder', 'AAA');
    }
  });
});

Upvotes: 1

Milind Anantwar
Milind Anantwar

Reputation: 82241

try this:

$('#list_field').change(function(){
   $('input[name="keyword"]').attr("placeholder", $(this).find("option:selected").text());
});

Working Demo

Upvotes: 1

Related Questions