Skip to content Skip to sidebar Skip to footer

Unable To Autofill Textarea Based On Selected Datalist Option

I want to autofill Address of the client in textarea based on input of client name in input field. I made a 'for loop' to get datalist of the clients name. And for address i fetch

Solution 1:

You can simply use the .val() method to add data to the textarea. Something like the below :-

$(function() {
    
  let textForTextArea = '';
  
    $('#ice-cream-choice').on('change', (e) => {
    e.preventDefault()
    textForTextArea = `${textForTextArea}${e.target.value}`
    $('#all-that-is-selected').val(textForTextArea)
  })
  
})
label , input {
  display : block;
  margin-bottom: 1rem;
}
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><labelfor="ice-cream-choice">Choose a flavor:</label><inputlist="ice-cream-flavors"id="ice-cream-choice"name="ice-cream-choice" /><datalistid="ice-cream-flavors"><optionvalue="Chocolate"><optionvalue="Coconut"><optionvalue="Mint"><optionvalue="Strawberry"><optionvalue="Vanilla"></datalist><textareaname=""id="all-that-is-selected"cols="30"rows="10"></textarea>

Post a Comment for "Unable To Autofill Textarea Based On Selected Datalist Option"